mcptokens

mcptokens

Provides tool to count token cost of any MCP server's tool definitions, enabling agents to assess cost before enabling.

Category
Visit Server

README

mcptokens

505 tokens in your agent's harness. One tool, inspect, that counts the tool-definition cost of any other MCP server (stdio or Streamable HTTP) before you enable it.

pip install mcptokens

<p> <a href="https://pypi.org/project/mcptokens/"><img src="https://img.shields.io/pypi/v/mcptokens.svg" alt="PyPI"></a> <a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-yellow.svg" alt="License: MIT"></a> <a href="https://www.python.org/downloads/"><img src="https://img.shields.io/badge/python-3.11+-blue.svg" alt="Python 3.11+"></a> <a href="https://github.com/dondai1234/mcptokens"><img src="https://img.shields.io/badge/Repo-dondai1234%2Fmcptokens-1f6feb.svg" alt="Repo"></a> </p>


Why

When your agent enables a new MCP server, its tools enter the agent's context on every turn. The cost compounds fast. mcptokens lets the agent ask is this server cheap enough? before flipping the switch.

Transports

Same tool, same response shape:

  • stdio (default): spawn a local process and speak JSON-RPC on its stdin/stdout.
  • streamable_http: POST initialize and tools/list to a remote MCP endpoint per MCP 2025-03-26. Server may reply via application/json (one message) or text/event-stream.

How

Add mcptokens to your agent's MCP config (Claude Code, Pi, OpenCode, Codex, ...). The agent gains one tool:

inspect(command=["python", "-m", "some_mcp_server"])
# stdio spawn argv, same as your MCP config

inspect(command=["hound"])
# pre-installed binary

inspect(
    transport="streamable_http",
    url="http://localhost:8080/mcp",
    headers={"Authorization": "Bearer ..."},  # optional
)
# remote MCP server

# Returns the same JSON shape every call:
# {ok, server, tool_count, wire_total_tokens,
#  tools: [{name, total}], encoding, elapsed_ms, version}

wire_total_tokens is the number to report. Use it BEFORE enabling a candidate server: a large value means don't enable.

The numbers

Self-cost on wire 505 tokens of cl100k_base
Tools exposed 1, named inspect
Transports stdio, streamable_http
Cross-platform Linux, macOS, Windows
Python 3.11+
Imports stdlib, tiktoken, mcp

Install

pip install mcptokens

Add mcptokens to your agent's mcpServers / mcp_servers. Done.

CLI (debug surface)

mcptokens python -m some_mcp_server     # human table
mcptokens --json python -m some_mcp_server   # pipeline-friendly JSON
mcptokens --timeout 30 python -m srv    # custom spawn, custom timeout
mcptokens serve                         # run as an MCP server
Flag Default Purpose
--encoding cl100k_base cl100k_base or o200k_base
--timeout 15 Per-server timeout in seconds (1 to 60)
--json false Output JSON instead of the table

License

MIT. pip install mcptokens from the canonical PyPI index.

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured