Skip to main content

Unofficial extension library for FastMCP 2.0 with patterns, practices, and utilities

Project description

FastMCP Extensions

Unofficial extension library for FastMCP 2.0 with patterns, practices, and utilities for building MCP servers.

Features

  • MCP Annotation Constants: Standard annotation hints (readOnlyHint, destructiveHint, idempotentHint, openWorldHint) following the FastMCP 2.2.7+ specification
  • Deferred Registration Decorators: @mcp_tool, @mcp_prompt, @mcp_resource decorators for organizing tools by domain with automatic domain detection
  • Registration Utilities: Functions to register tools, prompts, and resources with a FastMCP app, filtered by domain
  • Tool Testing Utilities: Helpers for testing MCP tools directly with JSON arguments (stdio and HTTP transports)
  • Tool List Measurement: Utilities for measuring tool list size to track context truncation issues
  • Prompt Helpers: Generic get_prompt_text helper for agents that cannot access prompt assets directly

Installation

pip install fastmcp-extensions

Or with uv:

uv add fastmcp-extensions

Quick Start

Using Annotation Constants

from fastmcp_extensions import (
    READ_ONLY_HINT,
    DESTRUCTIVE_HINT,
    IDEMPOTENT_HINT,
    OPEN_WORLD_HINT,
)

# Use in tool annotations
annotations = {
    READ_ONLY_HINT: True,
    IDEMPOTENT_HINT: True,
}

Using Deferred Registration

from fastmcp import FastMCP
from fastmcp_extensions import mcp_tool, mcp_resource, register_mcp_tools, register_mcp_resources

# Define tools with the decorator (domain auto-detected from filename)
@mcp_tool(read_only=True, idempotent=True)
def list_items() -> list[str]:
    """List all available items."""
    return ["item1", "item2"]

@mcp_resource("myserver://version", "Server version", "application/json")
def get_version() -> dict:
    """Get server version info."""
    return {"version": "1.0.0"}

# Register with FastMCP app
app = FastMCP("my-server")
register_mcp_tools(app)
register_mcp_resources(app)

Measuring Tool List Size

import asyncio
from fastmcp_extensions.measurement import measure_tool_list_detailed

async def check_tool_size():
    measurement = await measure_tool_list_detailed(app, server_name="my-server")
    print(measurement)
    # Output:
    # MCP Server: my-server
    # Tool count: 10
    # Total characters: 5,432
    # Average chars per tool: 543

asyncio.run(check_tool_size())

Testing Tools

from fastmcp_extensions.testing import call_mcp_tool, run_tool_test
import asyncio

# Call a tool programmatically
result = asyncio.run(call_mcp_tool(app, "list_items", {}))

# Or use the CLI helper
run_tool_test(app, "list_items", '{}')

Getting Prompt Text

from fastmcp_extensions.prompts import get_prompt_text
import asyncio

# Get prompt text for agents that can't access prompts directly
text = asyncio.run(get_prompt_text(app, "my_prompt", {"arg": "value"}))

Poe Tasks for MCP Servers

This library provides template scripts for common MCP development tasks. Copy these to your project and customize:

  • bin/test_mcp_tool.py - Test tools with JSON arguments via stdio
  • bin/test_mcp_tool_http.py - Test tools over HTTP transport
  • bin/measure_mcp_tool_list.py - Measure tool list size

Add to your poe_tasks.toml:

[tool.poe.tasks.mcp-tool-test]
help = "Test MCP tools directly with JSON arguments"
cmd = "python bin/test_mcp_tool.py"

[tool.poe.tasks.mcp-tool-test-http]
help = "Test MCP tools over HTTP transport"
cmd = "python bin/test_mcp_tool_http.py"

[tool.poe.tasks.mcp-measure-tools]
help = "Measure the size of the MCP tool list output"
cmd = "python bin/measure_mcp_tool_list.py"

API Reference

Annotations

Constant Description FastMCP Default
READ_ONLY_HINT Tool only reads data False
DESTRUCTIVE_HINT Tool modifies/deletes data True
IDEMPOTENT_HINT Repeated calls have same effect False
OPEN_WORLD_HINT Tool interacts with external systems True

Decorators

  • @mcp_tool(domain, read_only, destructive, idempotent, open_world, extra_help_text) - Tag a tool for deferred registration
  • @mcp_prompt(name, description, domain) - Tag a prompt for deferred registration
  • @mcp_resource(uri, description, mime_type, domain) - Tag a resource for deferred registration

Registration Functions

  • register_mcp_tools(app, domain, exclude_args) - Register tools with FastMCP app
  • register_mcp_prompts(app, domain) - Register prompts with FastMCP app
  • register_mcp_resources(app, domain) - Register resources with FastMCP app

Testing Utilities

  • call_mcp_tool(app, tool_name, args) - Call a tool asynchronously
  • list_mcp_tools(app) - List all available tools
  • run_tool_test(app, tool_name, json_args) - Run a tool test with JSON args
  • run_http_tool_test(http_server_command, port, tool_name, args, env) - Test over HTTP

Measurement Utilities

  • measure_tool_list(app) - Get (tool_count, total_chars) tuple
  • measure_tool_list_detailed(app, server_name) - Get detailed measurement
  • get_tool_details(app) - Get per-tool size breakdown

Prompt Utilities

  • get_prompt_text(app, prompt_name, arguments) - Get prompt text content
  • list_prompts(app) - List all available prompts

Development

# Install dependencies
uv sync --extra dev

# Run tests
uv run poe test

# Format and lint
uv run poe fix

# Run all checks
uv run poe check

License

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

fastmcp_extensions-0.1.1.tar.gz (138.9 kB view details)

Uploaded Source

Built Distribution

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

fastmcp_extensions-0.1.1-py3-none-any.whl (23.6 kB view details)

Uploaded Python 3

File details

Details for the file fastmcp_extensions-0.1.1.tar.gz.

File metadata

  • Download URL: fastmcp_extensions-0.1.1.tar.gz
  • Upload date:
  • Size: 138.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for fastmcp_extensions-0.1.1.tar.gz
Algorithm Hash digest
SHA256 f0acedfc37b5b34efb931f35c077034a6dc527ff86b8859c2c8988454e55c4b3
MD5 bab835fed26ec7e9296ef885e8f5ddc3
BLAKE2b-256 1cfd6fee1bf46a0cacbd186c5a4bd8c5b3d9b453910a30508c33d778172a08fe

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastmcp_extensions-0.1.1.tar.gz:

Publisher: publish.yml on airbytehq/fastmcp-extensions

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fastmcp_extensions-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for fastmcp_extensions-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 771da86d457b43925ac8e498ef302f73a379afaae9b578dbcda99a33e90aa2b9
MD5 512892e5ca00db5acd60653d4d3bb6a8
BLAKE2b-256 51af118418ba5b96d3b91540eb7eef6f79bd382a91773cfc9da928cd12cfaf84

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastmcp_extensions-0.1.1-py3-none-any.whl:

Publisher: publish.yml on airbytehq/fastmcp-extensions

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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