fcp核心
建筑共享框架 FCP 服务器——双TypeScript和Python实现。
它的作用
FCP(文件上下文协议)是一个用于构建MCP服务器的应用程序框架,它允许LLM通过基于动词的DSL与复杂的文件格式进行交互。fcp核心提供了每个fcp服务器共享的基础管道:标记化、操作解析、动词调度、事件源(撤销/重做)、会话生命周期、响应格式化以及将所有这些连接在一起的服务器工厂。FCP对于MCP就像React对于DOM一样——LLM在域操作中思考,FCP将它们呈现为目标格式。
快速示例
每个FCP服务器都暴露了4个MCP工具:
| 工具 | 用途 | 参数 |
|---|---|---|
{domain}(ops) | 批量突变 | ops: string[] |
{domain}_query(q) | 只读检查 | q: string |
{domain}_session(action) | 会话生命周期 | action: string |
{domain}_help() | 参考卡 | -- |
所有操作都遵循一个共同的语法:
VERB [positionals...] [key:value params...] [@selectors...]使用以下命令创建FCP服务器 createFcpServer:
import { createFcpServer } from '@ostk-ai/fcp-core';
const server = createFcpServer({
domain: 'midi',
verbs: { note: handleNote, chord: handleChord, tempo: handleTempo },
queries: { map: handleMap, describe: handleDescribe },
});Python等效于 create_fcp_server:
from fcp_core import create_fcp_server
server = create_fcp_server(
domain="midi",
verbs={"note": handle_note, "chord": handle_chord, "tempo": handle_tempo},
queries={"map": handle_map, "describe": handle_describe},
)安装
TypeScript (节点>=22):
npm install @ostk-ai/fcp-corepython (>= 3.11):
pip install fcp-core建筑
fcp-core在TypeScript和Python中都提供了这些模块:
| 模块 | 目的 |
|---|---|
| 分词器 | 基于报价的操作字符串拆分 |
| 解析操作 | 结构分类为动词、位置词、参数、选择词 |
| 动词注册表 | 域动词处理程序的注册和分派 |
| 事件日志 | 仅附加带有撤消/重做和检查点的事件源 |
| 会话 | 生命周期管理(新建、打开、保存、检查点、撤消、重做) |
| 格式化器 | 响应前缀约定(+ 创建, ~ 有联系的, * 被改进的, - 已删除) |
| 服务器 | 将所有东西连接到MCP服务器的工厂 |
完整的规格在 spec/:
发展
# TypeScript
cd typescript
npm install
npm test # vitest, 107 tests
npm run build # tsc
# Python
cd python
uv sync
uv run pytest # 112 tests许可证
麻省理工学院
