如今,部署为 LLM 工具的每个 Python 函数都必须以两种形式存在: 用于面向人类的客户端和 CI 管道的 HTTP 端点, 以及用于代理运行时(例如 Claude 和 Cursor)的 MCP 工具注册。这些表示共享业务逻辑,但在所有周围的机器(路由,验证,序列化,流,和模式维护),中存在分歧,并且随着底层代码的发展,它们会逐渐分开。我们提出了 HarnessAPI, 一个 Python 框架,它通过将类型化的技能文件夹视为单一事实来源来消除这种重复。从这个 http URL 加上 Pydantic 架构,,框架自动派生一个流式 HTTP 端点,其中包含服务器发送事件,、交互式 OpenAPI/Swagger UI, 和零配置 MCP 工具,,所有这些都由单个进程提供服务。双模式内容协商允许同一处理程序为 SSE 流和 JSON 返回客户端提供服务,而无需更改处理程序。动态代码生成机制确保 Pydantic 类型注释正确传播到 FastMCP的 检查层,,解决了阻止基于简单闭包注册的技术限制。使用 cloc, HarnessAPI 对六项代表性技能进行测量,与手动维护的双堆栈实现(FastAPI 服务器+ FastMCP 服务器) 相比,面向框架的样板文件减少了 74%。 HarnessAPI 子类 FastAPI, 继承了其完整的中间件, 依赖注入, 和部署生态系统。可以在此 https URL 和 PyPI (pip installharnessapi) 上获取

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 this http URL 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的 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 this https URL and on PyPI (pip install harnessapi)

科目: 人工智能 (cs.AI); 软件工程 (cs.SE)

Subjects: Artificial Intelligence (cs.AI); Software Engineering (cs.SE)