mcp_protocol

A set of rules and a Python structure for wrapping a service so AI clients can call its tools through MCP, an open protocol for connecting models to external tools. It uses server-sent events over HTTP for communication.

In plain words
What is it for?
Use it to define MCP tools with Python functions, run them through an HTTP server, and provide the standard /sse and /messages/ endpoints.
Why use it?
It gives developers a consistent way to expose functions, describe their inputs and outputs, and make the service reachable remotely. This avoids inventing a different connection and tool format for each service.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/fdueblab/micro-agent/mcp_protocol
Any agent
npx skills add fdueblab/Micro-Agent --skill mcp_protocol
Clone the repo
git clone --depth 1 https://github.com/fdueblab/Micro-Agent

Made for: Claude Code, Codex.

Per session 0 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 562 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.00562
Opus 5 $0.00000 $0.00281
Sonnet 5 $0.00000 $0.00112
Haiku 4.5 $0.00000 $0.00056

Measured 3d ago against content hash f2dbda753596, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

mcp_protocol scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 3d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

workspace/skills/mcp_protocol/SKILL.md · 58 lines

What it actually says

你是 MCP(Model Context Protocol)服务封装专家。封装 MCP 服务时,必须遵循以下规范:

传输方式

MCP 支持两种传输方式:

  • SSE(Server-Sent Events):基于 HTTP,适合远程部署。服务端暴露 /sse 端点和 /messages/ 挂载点。
  • stdio:基于标准输入输出,适合本地进程间通信。

本平台统一使用 SSE 传输方式。

server.py 标准结构

from mcp.server.fastmcp import FastMCP
from starlette.applications import Starlette
from starlette.routing import Mount, Route
from mcp.server.sse import SseServerTransport

mcp = FastMCP("服务名称")
sse = SseServerTransport("/messages/")

@mcp.tool()
async def tool_name(param1: str, param2: int = 0) -> str:
    """工具描述:简明说明这个工具的功能和用途。"""
    # 实现逻辑
    return result

async def handle_sse(request):
    async with sse.connect_sse(request.scope, request.receive, request._send) as streams:
        await mcp.run(streams[0], streams[1], mcp.create_initialization_options())

starlette_app = Starlette(routes=[
    Route("/sse", endpoint=handle_sse),
    Mount("/messages/", app=sse.get_asgi_app()),
])

if __name__ == "__main__":
    import uvicorn
    uvicorn.run(starlette_app, host="0.0.0.0", port=8000)

Tool 定义规范

  • 每个 @mcp.tool() 装饰的函数就是一个 MCP Tool
  • 函数名即 Tool name,应使用 snake_case
  • docstring 即 Tool description,必须清晰描述功能、参数含义、返回值
  • 参数类型注解会自动转为 JSON Schema(inputSchema)
  • 支持的参数类型:str, int, float, bool, list, dict
  • 有默认值的参数变为可选参数

关键注意事项

  • 每个功能函数都应封装为独立的 MCP Tool
  • 避免在 Tool 内部使用全局可变状态
  • 异步函数用 async def,同步函数也可以但推荐异步
  • Tool 返回值应为 str 类型(复杂结构用 JSON 序列化)
  • 错误处理:在 Tool 内部 try-except,返回错误描述而非抛异常
Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 3d ago First seen · 58 lines · 0 tokens per session scan A f2dbda753596

Subscribe to this mod's changes

mcp_protocol is a skill published in the GitHub repository fdueblab/Micro-Agent (99 stars, last pushed 21d ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 562 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.