Urgent.News

What's breaking now, across thousands of outlets.

Tech

Your MCP Server Burns Tokens Before It Does Anything: How to Measure and Trim It

TL;DR: Every tool your MCP server exposes has a name, a description and a JSON Schema, and most clients send all of them to the model on every request, before the user's question is even read. Stack a few servers and the tool list alone can eat a large slice of the context window. Below: a script that measures your server's real token cost, the four things that usually bloat it, and how to design…

When a client establishes a connection to an MCP server, it initiates a call to tools/list. In response, the server returns a list of tools, each accompanied by its name, description, and inputSchema. This information is then incorporated into the client's request, providing context for the model on which tools are available. This process of including tool definitions in the request is a fundamental aspect of the MCP protocol, and it raises concerns about the potential cost in terms of token usage.

There are three primary factors that contribute to the increased token consumption: each enabled server has its own tool list, the same tool list is repeated in every request, and the inclusion of numerous similar tools can lead to ambiguity and inaccurate predictions. As the number of tools grows, the likelihood of selecting the incorrect one increases, further exacerbating the issue. To address this problem, it is crucial to measure the actual token cost associated with the tool definitions.

A script has been developed to measure the real token cost incurred by the server's tool definitions. The script initiates the server using the official Python SDK and utilizes the Anthropic token counting endpoint to determine the number of input tokens added by the definitions. By comparing the token count with and without the tool definitions, the script provides a clear picture of the impact on the context window.

This measurement allows for an informed assessment of the server's tool list and facilitates the identification of areas for optimization.

The script provides a breakdown of the token usage for each tool, enabling developers to pinpoint the most resource-intensive tools. By focusing on these high-cost tools, developers can make targeted adjustments to reduce the overall token consumption without compromising the functionality and usability of the MCP server. This strategic approach to tool management not only optimizes token usage but also enhances the model's accuracy and efficiency, ensuring a more productive interaction between the client and the server.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Sec-Fetch-Site filters requests, but does not authorize users

Sec-Fetch-Site filters requests, but does not authorize users Security teams often need a cheap way to reject cross-site requests before a request reaches application code.

  • Sec-Fetch-Site indicates relationship between initiating site and requested resource origin
  • Header values include same-origin, same-site, cross-site, none
  • Sec-Fetch-Site does not authorize users or establish user identity

New K72 app helps Portuguese prepare 72-hour emergency kits for disasters

The app was created in Montijo by Carlos Batista, in coordination with this municipality's civil protection, but is intended for all Portuguese people and helps them assemble a "kit" for the first 72…

  • K72 app developed for Portuguese emergency kit preparation
  • App guides users in assembling 45 essential items
  • Provides family emergency plan and alerts feature

More from Tuesday 10 November →