@ppdocs/mcp 3.5.0 → 3.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/config.d.ts CHANGED
@@ -6,6 +6,7 @@ export interface PpdocsConfig {
6
6
  apiUrl: string;
7
7
  projectId: string;
8
8
  user: string;
9
+ agentId: string;
9
10
  source: 'env' | 'file';
10
11
  }
11
12
  export declare const PPDOCS_CONFIG_FILE = ".ppdocs";
package/dist/config.js CHANGED
@@ -16,7 +16,13 @@ function readEnvConfig() {
16
16
  if (!apiUrl)
17
17
  return null;
18
18
  const match = apiUrl.match(/\/api\/([^/]+)\/[^/]+\/?$/);
19
- return { apiUrl, projectId: match?.[1] || 'unknown', user: process.env.PPDOCS_USER || generateUser(), source: 'env' };
19
+ return {
20
+ apiUrl,
21
+ projectId: match?.[1] || 'unknown',
22
+ user: process.env.PPDOCS_USER || generateUser(),
23
+ agentId: process.env.PPDOCS_AGENT_ID || 'default',
24
+ source: 'env',
25
+ };
20
26
  }
21
27
  function readPpdocsFile() {
22
28
  const configPath = path.join(process.cwd(), '.ppdocs');
@@ -26,7 +32,7 @@ function readPpdocsFile() {
26
32
  const c = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
27
33
  if (!c.api || !c.projectId || !c.key)
28
34
  return null;
29
- return { apiUrl: `${c.api}/api/${c.projectId}/${c.key}`, projectId: c.projectId, user: c.user || generateUser(), source: 'file' };
35
+ return { apiUrl: `${c.api}/api/${c.projectId}/${c.key}`, projectId: c.projectId, user: c.user || generateUser(), agentId: c.agentId || process.env.PPDOCS_AGENT_ID || 'default', source: 'file' };
30
36
  }
31
37
  catch {
32
38
  return null;
package/dist/index.js CHANGED
@@ -39,8 +39,9 @@ async function main() {
39
39
  }
40
40
  const projectId = config?.projectId || 'pending';
41
41
  const user = config?.user || 'agent';
42
+ const agentId = config?.agentId || process.env.PPDOCS_AGENT_ID || 'default';
42
43
  const server = new McpServer({ name: `ppdocs [${projectId}]`, version: VERSION }, { capabilities: { tools: {} } });
43
- registerTools(server, projectId, user, (newProjectId, newApiUrl) => {
44
+ registerTools(server, projectId, user, agentId, (newProjectId, newApiUrl) => {
44
45
  console.error(`[kg_init] 项目已切换: ${newProjectId}`);
45
46
  });
46
47
  const transport = new StdioServerTransport();
@@ -15,7 +15,9 @@ import { getClient } from '../storage/httpClient.js';
15
15
  import { decodeObjectStrings } from '../utils.js';
16
16
  import { wrap, safeTool } from './shared.js';
17
17
  function sender(ctx) {
18
- return `${ctx.projectId}:${ctx.user}`;
18
+ return ctx.agentId && ctx.agentId !== 'default'
19
+ ? `${ctx.projectId}:${ctx.user}:${ctx.agentId}`
20
+ : `${ctx.projectId}:${ctx.user}`;
19
21
  }
20
22
  /** 提取 sender 中的 projectId */
21
23
  function senderProjectId(senderStr) {
@@ -12,4 +12,4 @@
12
12
  * 🏛️ 协作: kg_meeting (1个)
13
13
  */
14
14
  import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
15
- export declare function registerTools(server: McpServer, projectId: string, user: string, onProjectChange?: (newProjectId: string, newApiUrl: string) => void): void;
15
+ export declare function registerTools(server: McpServer, projectId: string, user: string, agentId: string, onProjectChange?: (newProjectId: string, newApiUrl: string) => void): void;
@@ -24,8 +24,8 @@ import { registerAnalyzerTools } from './analyzer.js';
24
24
  import { registerMeetingTools } from './meeting.js';
25
25
  import { registerFlowchartTools } from './flowchart.js';
26
26
  import { registerDocQueryTools } from './doc_query.js';
27
- export function registerTools(server, projectId, user, onProjectChange) {
28
- const ctx = createContext(projectId, user);
27
+ export function registerTools(server, projectId, user, agentId, onProjectChange) {
28
+ const ctx = createContext(projectId, user, agentId);
29
29
  // 🔗 初始化
30
30
  registerInitTool(server, ctx, onProjectChange || (() => { }));
31
31
  // 📊 导航
@@ -60,6 +60,7 @@ export function registerInitTool(server, ctx, onProjectChange) {
60
60
  // 4. 更新共享上下文 — 所有工具立刻获得新 projectId
61
61
  ctx.projectId = config.projectId;
62
62
  ctx.user = config.user;
63
+ ctx.agentId = process.env.PPDOCS_AGENT_ID || 'default';
63
64
  // 5. 通知主进程
64
65
  onProjectChange(config.projectId, config.apiUrl);
65
66
  return wrap(`✅ 项目上下文已初始化\n\n` +
@@ -6,9 +6,10 @@
6
6
  export interface McpContext {
7
7
  projectId: string;
8
8
  user: string;
9
+ agentId: string;
9
10
  }
10
11
  /** 创建可变上下文对象 (工具闭包捕获此对象的引用,kg_init 更新其属性) */
11
- export declare function createContext(projectId: string, user: string): McpContext;
12
+ export declare function createContext(projectId: string, user: string, agentId?: string): McpContext;
12
13
  export declare function wrap(text: string): {
13
14
  content: {
14
15
  type: "text";
@@ -3,8 +3,8 @@
3
3
  * 合并原 helpers.ts + 新增 safeTool / withCross 模式
4
4
  */
5
5
  /** 创建可变上下文对象 (工具闭包捕获此对象的引用,kg_init 更新其属性) */
6
- export function createContext(projectId, user) {
7
- return { projectId, user };
6
+ export function createContext(projectId, user, agentId = 'default') {
7
+ return { projectId, user, agentId };
8
8
  }
9
9
  // ==================== MCP 返回包装 ====================
10
10
  export function wrap(text) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ppdocs/mcp",
3
- "version": "3.5.0",
3
+ "version": "3.6.0",
4
4
  "description": "ppdocs MCP Server - Knowledge Graph for Claude",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",