Token导航 LogoToken导航TokenDH.com
MCP Coded Tools logo
开发工具stdio官方级别未说明来源级核验

MCP Coded Tools

MCP Server

自动从MCP服务器生成可发现的Python代码,供AI代理工具使用,减少令牌使用并提高效率。

工具数

0

提示词数

0

GitHub Stars

3

资源数

0
代码生成自动化Python本地部署STDIO

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

作者 / 组织

bluman1

提供方

bluman1

最后核验

2026/5/17 20:23

快速接入

先看主来源和安装命令,再打开仓库或文档;下面只保留这个条目的关键接入事实。

命令预览

pip install mcp-coded-tools

详细介绍

mcp编码工具

](https://badge.fury.io/py/mcp-coded-tools) ](https://pypi.org/project/mcp-coded-tools/) ![License: MIT](https://opensource.org/licenses/MIT) ![CI](https://github.com/bluman1/mcp-coded-tools/actions)

从MCP服务器生成可发现的代码,以供AI代理工具使用。

为什么?

模型上下文协议(MCP) 让AI代理连接到外部工具和数据。然而,正如Anthropic的 工程岗位 解释说,将数百或数千个工具定义直接加载到代理的上下文窗口中效率低下:

  • 工具定义消耗了过多的令牌(大型工具集消耗了10万多个令牌)
  • 中间结果反复流过上下文窗口
  • 代理商在规模上变得更慢、更贵

解决方案:将MCP服务器表示为 *代码API* 代理可以通过文件系统接口发现和使用。这种方法将令牌使用率降低了98.7%,同时实现了更强大的代理工作流。

问题:为每个MCP工具手动编写包装器代码是乏味的。

mcp编码工具:从任何MCP服务器自动生成可发现的Python代码。

安装

pip install mcp-coded-tools

快速开始

CLI使用情况

# Generate code from popular MCP servers
mcp-coded-tools generate \
  --command "npx -y @modelcontextprotocol/server-github" \
  --output ./servers \
  --server-name github

# Generate from multiple servers for complete workflows
mcp-coded-tools generate \
  --command "npx -y @modelcontextprotocol/server-github" \
  --command "npx -y @modelcontextprotocol/server-postgres" \
  --command "python slack_mcp_server.py" \
  --output ./servers

# Watch mode for development (auto-regenerate on changes)
mcp-coded-tools generate \
  --command "python ./my_mcp_server.py" \
  --output ./tools \
  --watch

💡 人口_MCP_SERVERS.md 适用于50多个流行的服务器和现实世界的用例!

💡 WATCH_MODE.md 用于开发过程中的自动再生!

Python API

import asyncio
from mcp-coded-tools import MCPCodeGenerator

async def main():
    generator = MCPCodeGenerator()

    # Connect to MCP server and generate code
    await generator.connect_and_scan([
        "npx", "-y", "@modelcontextprotocol/server-gdrive"
    ])

    generator.generate_code(
        output_dir="./servers",
        server_name="google_drive"
    )

    print("✓ Generated discoverable code!")

asyncio.run(main())

生成什么

servers/
├── google_drive/
│   ├── __init__.py
│   ├── get_document.py
│   ├── list_files.py
│   └── ...
├── salesforce/
│   ├── __init__.py
│   ├── update_record.py
│   └── ...
└── _client.py

每个工具都变成一个类型化的Python函数:

# servers/google_drive/get_document.py
from typing import Optional, Dict, Any
from .._client import call_mcp_tool

async def get_document(
    document_id: str,
    fields: Optional[str] = None
) -> Dict[str, Any]:
    """
    Retrieves a document from Google Drive
    """
    return await call_mcp_tool(
        'gdrive_getDocument',
        {'documentId': document_id, 'fields': fields}
    )

代理使用

代理通过探索文件系统来发现工具:

# Agent lists available servers
import os
servers = os.listdir('./servers')
# ['google_drive', 'salesforce', ...]

# Agent reads a specific tool
with open('./servers/google_drive/get_document.py') as f:
    tool_def = f.read()
    # Understands parameters, types, description

# Agent writes code to use tools
import servers.google_drive as gdrive
import servers.salesforce as sf

async def sync_meeting_notes():
    doc = await gdrive.get_document(document_id="abc123")
    
    await sf.update_record(
        object_type="Lead",
        record_id="xyz789",
        data={"Notes": doc['content']}
    )

特性

  • 自动代码生成 从任何MCP服务器
  • 键入提示 为了更好地支持IDE和理解代理
  • 文档字符串 摘自MCP工具描述
  • 多个服务器 具有自动名称空间分离功能
  • CLI和Python API 为了灵活性
  • 错误处理 详细记录
  • 异步支持 用于并发工具执行

配置

服务器发现

默认情况下,会分析工具名称以提取服务器前缀:

  • gdrive_getDocumentgdrive 服务器
  • salesforce_updateRecordsalesforce 服务器

用显式服务器名称覆盖:

generator.generate_code(
    output_dir="./servers",
    server_name="my_custom_name"
)

自定义模板

使用Jinja2模板自定义生成的代码:

generator = MCPCodeGenerator(
    template_dir="./my_templates"
)

运作原理

  1. 连接:通过stdio、HTTP或SSE建立与MCP服务器的连接
  2. 反思:使用MCP协议向服务器查询所有可用工具
  3. 解析:提取工具名称、描述和JSON模式
  4. 生成:创建具有正确导入的类型化Python函数
  5. 组织:在可发现的文件系统层次结构中构造代码

用例

🏢 企业事件响应

跨多个系统自动化DevOps工作流程:

mcp-coded-tools generate \
  --command "npx -y @modelcontextprotocol/server-postgres" \
  --command "npx -y @modelcontextprotocol/server-github" \
  --command "python slack_mcp_server.py" \
  --output ./devops_tools

工作流程: 查询错误→ 创建问题→ 通知团队 代币节省: 98%(15万)→ 3K代币) 成本影响: $3.00 → $0.06 每次事故

📊 数据分析管道

无上下文污染地处理数百万行:

from data_tools.postgres import execute_query
from data_tools.slack import post_message

# Query 1M rows - stays in execution environment!
rows = await execute_query(
    query="SELECT * FROM transactions WHERE date > NOW() - INTERVAL '30 days'"
)

# Process data in code (never enters context)
import pandas as pd
df = pd.DataFrame(rows)
summary = df.groupby('user_id')['amount'].sum()

# Only summary goes to context
await post_message(
    channel='analytics',
    text=f"Processed {len(df):,} transactions, total: ${summary.sum():,.2f}"
)

规模: 过程TB,而非MB 投资回报率: 每天500次查询,每年1.09亿美元

🤖 自动代码审查

在人工智能的帮助下大规模审查PR:

mcp-coded-tools generate \
  --command "npx -y @modelcontextprotocol/server-github" \
  --command "npx -y @modelcontextprotocol/server-filesystem" \
  --command "npx -y @modelcontextprotocol/server-sequential-thinking" \
  --output ./code_review_tools

影响: 每天审查1000个PR,质量始终如一

📚 示例/真实世界工作流.py 5个完整的生产示例!

发展

# Clone repository
git clone https://github.com/bluman1/mcp-coded-tools.git
cd mcp-coded-tools

# Install in development mode
pip install -e ".[dev]"

# Run tests
pytest

# Format code
black src/ tests/
ruff check src/ tests/

# Type checking
mypy src/

贡献

欢迎投稿!请阅读 贡献.md 作为指导方针。

许可证

MIT许可证-请参阅 许可证 了解详情。

鸣谢

灵感来自Anthropic MCP代码执行工程岗.

由Michael Ogundare为MCP社区建造。

目录标签

目录标签

代码生成自动化Python本地部署STDIOAI工具MCP协议

接入字段

传输方式(transport,传输协议)

stdio

鉴权方式(authType,认证方式)

none

工具数量(toolCount,工具数)

0

资源数量(resourceCount,资源数)

0

提示词数量(promptCount,提示词数)

0

权限和风险

stdionone部署方式未说明

接入前请确认传输方式、认证方式和部署位置,并根据实际工具能力限制访问范围。

安装前确认

不要直接授予不必要的文件、网络或账号权限;先核对安装命令和配置内容。

来源信息

继续浏览同类 MCP