Show HN: PolyMCP – 轻松将 Python/TS 函数暴露为 MCP 工具

1作者: justvugg6 天前
我构建了 PolyMCP,目的是为了让将现有函数暴露为 MCP 工具变得轻而易举,无需重写逻辑或添加大量粘合代码。 目标:获取“普通”的 Python 或 TypeScript 函数,并立即让它们可供 MCP 客户端(Claude Desktop、代理、Ollama 等)使用。 Python 示例 ```python from polymcp.polymcp_toolkit import expose_tools def greet(name: str) -> str: """打招呼。""" return f"你好,{name}!" def add(a: int, b: int) -> int: """加两个数。""" return a + b app = expose_tools([greet, add], title="我的 MCP 工具") ``` 运行方式: ```bash uvicorn server:app --reload ``` MCP 端点出现在: * /mcp/list\_tools * /mcp/invoke TypeScript 示例 ```typescript import { z } from "zod"; import { tool, exposeTools } from "polymcp"; const uppercaseTool = tool({ name: "uppercase", description: "将文本转换为大写", inputSchema: z.object({ text: z.string() }), function: async ({ text }) => text.toUpperCase(), }); const app = exposeTools([uppercaseTool], { title: "文本工具" }); app.listen(3000); ``` 更多“真实”示例(Python) ```python import pandas as pd from polymcp.polymcp_toolkit import expose_tools def calculate_commissions(sales_data: list[dict]): df = pd.DataFrame(sales_data) df["commission"] = df["sales_amount"] * 0.05 return df.to_dict(orient="records") app = expose_tools([calculate_commissions], title="业务工具") ``` 您将获得 * 以最小的改动重用现有代码 * MCP 兼容(Claude Desktop、代理、Ollama 等) * 支持 HTTP、stdio 和 WASM * 自动输入验证 * 基本的生产特性(预算、重试、编辑、日志) * 用于测试和监控的内置检查器 安装 * Python:pip install polymcp * TypeScript:克隆仓库 → cd polymcp-ts → npm install → npm run build 仓库: [https://github.com/poly-mcp/Polymcp](https://github.com/poly-mcp/Polymcp) 很好奇,如果这么容易,人们会首先暴露什么样的函数。 非常欢迎反馈。
查看原文
I built PolyMCP to make it trivial to expose existing functions as MCP tools, without rewriting logic or adding much glue code.<p>The goal: take “normal” Python or TypeScript functions and instantly make them usable by MCP clients (Claude Desktop, agents, Ollama, etc.).<p>Python example<p>from polymcp.polymcp_toolkit import expose_tools<p>def greet(name: str) -&gt; str: &quot;&quot;&quot;Say hello.&quot;&quot;&quot; return f&quot;Hello, {name}!&quot;<p>def add(a: int, b: int) -&gt; int: &quot;&quot;&quot;Add two numbers.&quot;&quot;&quot; return a + b<p>app = expose_tools([greet, add], title=&quot;My MCP Tools&quot;)<p>Run with:<p>uvicorn server:app --reload<p>MCP endpoints appear at: • &#x2F;mcp&#x2F;list_tools • &#x2F;mcp&#x2F;invoke<p>TypeScript example<p>import { z } from &quot;zod&quot;; import { tool, exposeTools } from &quot;polymcp&quot;;<p>const uppercaseTool = tool({ name: &quot;uppercase&quot;, description: &quot;Convert text to uppercase&quot;, inputSchema: z.object({ text: z.string() }), function: async ({ text }) =&gt; text.toUpperCase(), });<p>const app = exposeTools([uppercaseTool], { title: &quot;Text Tools&quot; }); app.listen(3000);<p>More “real” example (Python)<p>import pandas as pd from polymcp.polymcp_toolkit import expose_tools<p>def calculate_commissions(sales_data: list[dict]): df = pd.DataFrame(sales_data) df[&quot;commission&quot;] = df[&quot;sales_amount&quot;] * 0.05 return df.to_dict(orient=&quot;records&quot;)<p>app = expose_tools([calculate_commissions], title=&quot;Business Tools&quot;)<p>What you get • Reuse existing code with minimal changes • MCP-compatible (Claude Desktop, agents, Ollama, etc.) • HTTP, stdio, and WASM support • Automatic input validation • Basic production features (budgets, retries, redaction, logs) • Built-in inspector for testing and monitoring<p>Install • Python: pip install polymcp • TypeScript: clone repo → cd polymcp-ts → npm install → npm run build<p>Repo: <a href="https:&#x2F;&#x2F;github.com&#x2F;poly-mcp&#x2F;Polymcp" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;poly-mcp&#x2F;Polymcp</a><p>Curious what kind of function people would expose first if it was this easy. Feedback very welcome.