模型上下文协议集成工具

mcp.core 是一个平台无关的模型上下文协议(MCP)集成工具,提供双向MCP功能,使AI助手能够使用外部工具或外部AI助手访问LAMA功能。

  • by juergengeck
  • TypeScript
  • 本地部署
  • 更新于
在 GitHub 查看 juergengeck/mcp.core

使用说明

mcp.core

LAMA的平台无关模型上下文协议(MCP)集成。

概述

mcp.core 提供双向MCP集成:

  • 入境MCPLAMA中的AI助手可以使用外部MCP工具(文件系统等)
  • 出站MCP:外部AI助手(Claude Desktop)可以访问LAMA功能

建筑

┌─────────────────────────────────────────────────────┐
│                   mcp.core                          │
│                                                     │
│  ┌────────────────────────────────────────────┐   │
│  │  MCPManager (Inbound)                      │   │
│  │  • Connects to external MCP servers        │   │
│  │  • Tool discovery and execution            │   │
│  │  • Tool call auditability                  │   │
│  └────────────────────────────────────────────┘   │
│                                                     │
│  ┌────────────────────────────────────────────┐   │
│  │  MCPLamaServer (Outbound)                  │   │
│  │  • Plan Registry pattern                   │   │
│  │  • Dynamic tool discovery                  │   │
│  │  • Meta-tools (discover_plans, call_plan)  │   │
│  └────────────────────────────────────────────┘   │
│                                                     │
│  ┌────────────────────────────────────────────┐   │
│  │  Core Tools                                │   │
│  │  • MemoryTools - LLM memory storage        │   │
│  │  • AssemblyTools - Supply/Demand/Plans     │   │
│  │  • PlanRegistry - Dynamic plan discovery   │   │
│  └────────────────────────────────────────────┘   │
└─────────────────────────────────────────────────────┘

目录结构

mcp.core/
├── src/
│   ├── server/              # MCP server implementations
│   │   ├── MCPManager.ts    # Inbound: external tool management
│   │   └── MCPLamaServer.ts # Outbound: LAMA tool exposure
│   ├── tools/               # Tool implementations
│   │   ├── MemoryTools.js   # Memory storage and retrieval
│   │   ├── AssemblyTools.js # Supply/Demand/Assembly/Plan ops
│   │   ├── PlanRegistry.ts  # Dynamic plan registration
│   │   └── PlanMetaTools.ts # Plan discovery meta-tools
│   ├── interface/           # Tool definitions & execution
│   │   ├── tool-definitions.ts  # MCP tool schemas
│   │   ├── tool-executor.ts     # Tool execution engine
│   │   └── mcp-tool-interface.ts # Platform abstraction
│   ├── recipes/             # ONE.core data models
│   │   └── mcp-recipes.ts   # MCP storage schemas
│   └── types/               # TypeScript definitions
├── README.md                # This file
└── MCP-SERVER.md           # Standalone server docs (legacy)

关键概念

1.计划注册表模式

代替硬编码工具定义, mcp.core 使用a 计划注册表 哪里:

  • 平台实现(lama.cube、lama.browser)注册计划实例
  • 计划是与平台无关的业务逻辑(ChatPlan、ContactsPalan等)
  • MCP工具动态发现和调用计划方法
  • 没有静态工具列表-所有内容都在运行时发现

例子:

import { planRegistry } from '@mcp/core';

// Register a plan instance
planRegistry.registerPlan(
  'chat',           // Plan name
  'messaging',      // Category
  chatPlanInstance, // Plan instance with methods
  'Chat and messaging operations'
);

// MCP clients can now discover and call chat plan methods

2.双向MCP

入站(外部工具→ 喇嘛艾):

import { mcpManager } from '@mcp/core';

// MCPManager connects to external MCP servers
await mcpManager.init();

// AI assistants can now use tools like:
// - filesystem:read_file
// - filesystem:write_file
// - memory:store
// - assembly:createSupply

出站(外部AI→ 喇嘛):

import { LamaMCPServer } from '@mcp/core';

// Expose LAMA functionality via MCP
const mcpServer = new LamaMCPServer(nodeOneCore);
await mcpServer.start();

// External clients (Claude Desktop) can now use:
// - discover_plans (see what LAMA can do)
// - call_plan (execute LAMA operations)
// - memory_* (access LAMA memories)

3.元工具

外部MCP客户端通过元工具发现功能:

  • discover_plans -列出所有可用的计划和方法
  • call_plan -执行特定的计划方法
  • 无需硬编码工具列表

流量:

  1. 客户电话 discover_plans → 使用“sendMessage”方法查看“聊天”计划
  2. 客户电话 call_plan 随着 {plan: "chat", method: "sendMessage", params: {...}}
  3. 计划到ChatPlan.sendMessage()的注册表路由

用法

入站MCP(AI使用外部工具)

在lama.cube中用于让AI助手访问文件系统、内存等。

import { mcpManager } from '@mcp/core';

// Initialize in Node.js main process
mcpManager.setNodeOneCore(nodeOneCore);
await mcpManager.init();

// Get available tools
const tools = mcpManager.getAvailableTools();
// Returns: filesystem:read_file, memory:store, assembly:createSupply, etc.

// Execute a tool
const result = await mcpManager.executeTool(
  'filesystem:read_file',
  { path: '/path/to/file.txt' }
);

// Store tool call for audit
await mcpManager.storeToolCall({
  id: 'tool-call-123',
  toolName: 'filesystem:read_file',
  parameters: { path: '/path/to/file.txt' },
  result,
  timestamp: Date.now(),
  topicId: 'conversation-id'
});

出站MCP(外部AI访问LAMA)

用于独立MCP服务器,将LAMA暴露给Claude Desktop。

import { LamaMCPServer } from '@mcp/core';
import { planRegistry, registerLamaCorePlans } from '@mcp/core';

// Register plans with the registry
const deps = { nodeOneCore, aiAssistantModel };
registerLamaCorePlans(deps);

// Register platform-specific plans
const chatPlan = new ChatPlan(nodeOneCore);
planRegistry.registerPlan('chat', 'messaging', chatPlan);

// Start MCP server (listens on stdio)
const mcpServer = new LamaMCPServer(nodeOneCore);
await mcpServer.start();

// External clients can now:
// - discover_plans → see chat, contacts, ai, etc.
// - call_plan → execute LAMA operations

工具接口(平台无关)

对于平台无关的工具定义和执行:

import { MCPToolInterface } from '@mcp/core';

const toolInterface = new MCPToolInterface(mcpServer, nodeOneCore);

// Get tool definitions in MCP format
const tools = toolInterface.getToolDefinitions();

// Execute a tool
const result = await toolInterface.executeTool('memory:store', {
  content: 'User prefers dark mode',
  category: 'preferences'
});

数据模型(ONE.core)

所有存储为版本化ONE.core对象的MCP数据:

MCP服务器

{
  $type$: 'MCPServer',
  name: string,        // Server ID
  command: string,     // Executable
  args: string[],
  description: string,
  enabled: boolean,
  createdAt: number,
  updatedAt: number
}

MCPServer配置

{
  $type$: 'MCPServerConfig',
  userEmail: string,   // User ID
  servers: SHA256IdHash<MCPServer>[],
  updatedAt: number
}

MCPTopicConfig

{
  $type$: 'MCPTopicConfig',
  topicId: string,     // Conversation ID
  inboundEnabled: boolean,   // AI can use tools
  outboundEnabled: boolean,  // External access
  allowedTools?: string[],
  createdAt: number,
  updatedAt: number
}

MCPToolCall

{
  $type$: 'MCPToolCall',
  id: string,
  toolName: string,
  parameters: string,  // JSON
  result?: string,     // JSON
  error?: string,
  timestamp: number,
  duration?: number,
  topicId: string,
  messageHash?: string
}

可用工具

入站工具(外部→ 喇嘛艾)

文件系统 (来自2台服务器的28个工具):

  • filesystem:read_file, filesystem:write_file, filesystem:edit_file
  • filesystem:list_directory, filesystem:directory_tree
  • filesystem:create_directory, filesystem:move_file
  • filesystem-home:* (相同的工具,不同的根)

记忆 (3个工具):

  • memory:store -存储信息以供以后检索
  • memory:recall -检索存储的记忆
  • memory:search -按关键字搜索记忆

汇编 (9个工具):

  • assembly:createSupply -创建供应对象
  • assembly:createDemand -创建Demand对象
  • assembly:createAssembly -供需匹配
  • assembly:createPlan -制定执行计划
  • assembly:createStory -创建用户故事
  • assembly:queryAssemblies, assembly:queryPlans
  • assembly:getAssembly, assembly:getPlan

出站工具(LAMA→ 外部AI)

元工具:

  • discover_plans -列出所有可用的计划和方法
  • call_plan -执行计划方法

内存工具:

  • memory_store, memory_recall, memory_search
  • subject_extract, subject_search, subject_list

计划 (通过以下方式动态发现 discover_plans):

  • chat -发送/接收消息,列出对话
  • contacts -获取/搜索联系人
  • ai -人工智能模型管理和生成
  • assembly -供应/需求/组装/计划操作
  • 还有更多。..

集成示例

lama.cube(电子)

// main/core/node-one-core.ts
import { mcpManager } from '@mcp/core';

// Initialize MCP manager after ONE.core is ready
mcpManager.setNodeOneCore(nodeOneCore);
await mcpManager.init();

// Register plans for outbound MCP
import { planRegistry } from '@mcp/core';
import { ChatPlan } from '@chat/core/plans/ChatPlan';

const chatPlan = new ChatPlan(nodeOneCore);
planRegistry.registerPlan('chat', 'messaging', chatPlan);

拉马布罗泽

// Browser can't run Node.js MCP servers
// But can use HTTP proxy to access LAMA MCP functionality
// (Future implementation)

独立MCP服务器

看 MCP-SERVER.md 用于连接到LAMA API的独立服务器设置。

安全注意事项

入站MCP(AI使用工具)

  • 每次对话控制(MCPTopicConfig)
  • 工具调用已审核(MCPToolCall存储)
  • 工具仅在明确启用时执行

出站MCP(外部AI访问LAMA)

⚠️ 未实施访问控制

当前状态:

  • 外部MCP客户端可以完全访问所有LAMA数据
  • 没有每个聊天或每个程序集的访问权限
  • 无客户端身份验证
  • 仅与个人计算机上的受信任客户端一起使用

生产所需:

  • MCPClientAccess验证(每次聊天、每次程序集授权)
  • 具有加密验证的客户端身份验证
  • MCPClientAudit记录所有操作
  • 用于管理客户端访问权限的UI
  • 访问撤销支持

访问控制数据模型和实施计划见lama.cube MCP.md。

依赖项

  • @modelcontextprotocol/sdk -MCP协议实现
  • @refinio/one.core -存储和版本控制

平台要求

  • MCPManager:需要Node.js(通过stdio使用子进程)
  • MCPLamaServer:需要Node.js(使用stdio传输)
  • 工具和界面:平台无关(可以在任何地方运行)

相关文件

发展

建筑

npm run build

测试

# Test inbound MCP
node -e "import('@mcp/core').then(m => m.mcpManager.debugState())"

# Test plan registry
node -e "import('@mcp/core').then(m => console.log(m.planRegistry.getAllPlans()))"

迁移说明

来自旧工具系统

以前,工具在工具定义中是硬编码的。现在:

  1. 注册计划 而不是定义工具:

    // Old: Define each tool manually
    // New: Register plan, tools auto-discovered
    planRegistry.registerPlan('chat', 'messaging', chatPlan);
    
  2. 使用元工具 为了发现:

    // Old: Client needs to know all tools upfront
    // New: Client calls discover_plans to see what's available
    
  3. 工具执行 路线通过计划注册表:

    // Old: Direct tool execution
    // New: call_plan routes to plan method
    

许可证

LAMA项目的一部分。