HarnessAPI: 一种以技能为中心的统一流式API和MCP工具框架
HarnessAPI: A Skill-First Framework for Unified Streaming APIs and MCP Tools
AI总结:
本文提出HarnessAPI,一种以技能为中心的框架,通过将类型化的技能文件夹作为单一真相源,消除了流式API和MCP工具之间的重复代码,减少了74%的框架层面的样板代码。
摘要:
如今,每一个作为LLM工具部署的Python函数必须以两种形式存在:一种是面向人类客户端和CI流水线的HTTP端点,另一种是用于代理运行时如Claude和Cursor的MCP工具注册。这两种表示共享业务逻辑,但在周围机器(路由、验证、序列化、流式传输和模式维护)上却存在差异,并且随着底层代码的变化而逐渐分离。我们提出了HarnessAPI,一种Python框架,通过将类型化的技能文件夹作为单一真相源来消除这种重复。从一个handler.py加上Pydantic模式,该框架可以自动推导出一个流式HTTP端点,具有Server-Sent Events,一个交互式的OpenAPI/Swagger UI,以及一个零配置的MCP工具,所有都从单一进程提供。双模式内容协商让相同的处理程序可以服务于SSE流式传输和JSON返回客户端,而无需更改处理程序。动态代码生成机制确保Pydantic类型注解正确传播到FastMCP的检查层,解决了一个技术限制,该限制阻止了基于闭包的简单注册。通过六个代表性技能的cloc测量,与手动维护的双栈实现(FastAPI服务器+FastMCP服务器)相比,HarnessAPI减少了74%的框架层面的样板代码。HarnessAPI继承了FastAPI的全部中间件、依赖注入和部署生态系统。它可在https://github.com/edwinjosechittilappilly/harnessapi上获得,并在PyPI(pip install harnessapi)中可用。
英文摘要:
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)
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。