做 LLM 工具部署的开发者终于可以告别 HTTP 和 MCP 两套代码的重复维护了——HarnessAPI 用一个技能文件夹自动生成所有接口,减少 74% 样板代码,值得直接试试。
HarnessAPI 是一个 Python 框架,旨在解决 LLM 工具部署中 HTTP 端点与 MCP 工具注册重复维护的问题。它通过将类型化的技能文件夹作为单一事实来源,从 handler.py 和 Pydantic 模式自动生成流式 HTTP 端点、交互式 OpenAPI/Swagger UI 和零配置 MCP 工具。该框架支持双模式内容协商,无需修改处理器即可同时服务 SSE 流和 JSON 返回客户端。动态代码生成机制确保 Pydantic 类型注解正确传播到 FastMCP 的检查层,解决了基于闭包注册的技术限制。在六个代表性技能上测试,HarnessAPI 相比手动维护的双栈实现减少了 74% 的框架相关样板代码。
HarnessAPI: A Skill-First Framework for Unified Streaming APIs and MCP Tools
Every Python function deployed as an LLM tool must today exist in two forms: an HTTP endpoint for human-facing clients and CI pipelines, and an MCP tool registration for agent runtimes such as Claude and Cursor. These representations share business logic yet diverge in all the surrounding machinery (routing, validation, serialisation, streaming, and schema maintenance), and they drift apart as the underlying code evolves. We present HarnessAPI, a Python framework that eliminates this duplication by treating a typed skill folder as the single source of truth. From one handler.py plus Pydantic schemas, the framework automatically derives a streaming HTTP endpoint with Server-Sent Events, an interactive OpenAPI/Swagger UI, and a zero-configuration MCP tool, all served from a single process. Dual-mode content negotiation lets the same handler serve SSE-streaming and JSON-returning clients with no handler changes. A dynamic code-generation mechanism ensures Pydantic type annotations propagate correctly to FastMCP's inspection layer, resolving a technical limitation that prevents naive closure-based registration. Measured across six representative skills using cloc, HarnessAPI reduces framework-facing boilerplate by 74% compared with a manually maintained dual-stack implementation (FastAPI server + FastMCP server). HarnessAPI subclasses FastAPI, inheriting its full middleware, dependency-injection, and deployment ecosystem. It is available at https://github.com/edwinjosechittilappilly/harnessapi and on PyPI (pip install harnessapi)