Skip to main content

Helper toolkit to build MCP servers

Project description

mcp-tool

English | 中文


mcp-tool is a small toolkit for building Model Context Protocol (MCP) servers in Python.

It provides a decorator-based tool registry, a JSON-RPC 2.0 handler, and WebSocket / stdio transports so you can expose your tools to MCP-compatible clients.

Features

  • JSON-RPC 2.0 handling with initialize, tools/list, and tools/call
  • Async @tool decorator for registering MCP tools
  • In-memory registry and /doc endpoint to list available tools
  • WebSocket transport built with FastAPI (/ws, /healthz, /doc)
  • stdio transport for local integrations over stdin/stdout
  • Typer-based CLI to run your MCP server in service or stdio mode

Installation

For local development:

python -m venv .venv
source .venv/bin/activate
pip install -e .

OR

pip install mcp-tool-tingz

Defining tools

Use the @tool decorator exported from the package:

from mcp_tool import tool

@tool(description="Simple ping tool to verify MCP connectivity")
async def ping(message: str = "pong") -> str:
    return f"MCP: {message}"

You can see a more complete example in mcp-tool/demo_app.py.

Running the server

The CLI exposes a single run command with two modes: service (WebSocket) and stdio.

WebSocket service mode

Start an MCP server over WebSocket:

mcp-tool run --mode service --host 0.0.0.0 --port 8765 --app mcp_tool.demo_app
  • --app points to a Python module or file that registers tools (via @tool).
  • The server exposes:
    • GET /healthz — health check
    • GET /doc — tools documentation (from the registry plus server metadata)
    • WS /ws — JSON-RPC 2.0 over WebSocket

You can point an MCP-compatible client at ws://localhost:8765/ws.

stdio mode

To run the same tools over stdio (useful for editor or local CLI integrations):

mcp-tool run --mode stdio --app mcp_tool.demo_app

The process reads and writes JSON-RPC messages framed with Content-Length headers on stdin/stdout.

JSON-RPC protocol

mcp-tool follows JSON-RPC 2.0 and implements:

  • initialize — returns server metadata and capabilities
  • tools/list (and tools.list) — lists all registered tools and their schemas
  • tools/call (and tools.call) — calls a registered tool with arguments

A typical successful response looks like:

{"jsonrpc": "2.0", "id": "uuid", "result": {...}}

An error response looks like:

{"jsonrpc": "2.0", "id": "uuid", "error": {"code": -32603, "message": "Internal error"}}

License

This project is licensed under the MIT License. See LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mcp_tool_tingz-0.1.3.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcp_tool_tingz-0.1.3-py3-none-any.whl (13.3 kB view details)

Uploaded Python 3

File details

Details for the file mcp_tool_tingz-0.1.3.tar.gz.

File metadata

  • Download URL: mcp_tool_tingz-0.1.3.tar.gz
  • Upload date:
  • Size: 10.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mcp_tool_tingz-0.1.3.tar.gz
Algorithm Hash digest
SHA256 d7b12c023825b9601e648fff3bcc3df077e92e9b9da10b051f471f169d6171fa
MD5 743847973baddf3f44f1333f301cd605
BLAKE2b-256 ef24b55b5990f03c79894afb78c5826f525c6546b8fd6dda3f63b94a9ce6ed11

See more details on using hashes here.

File details

Details for the file mcp_tool_tingz-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: mcp_tool_tingz-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 13.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mcp_tool_tingz-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 31fcf560b6f54ea62aa664b04bc6e223e9cacd568150c3e0f24d17e9f02f74d5
MD5 ea24b18ddc415ac331442ca7bb6a5409
BLAKE2b-256 7c93d931ab0fe513ae2c02a0e98be2879412dca7eee4bb284bd13e10226547e0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page