@musashishao/agent-kit 1.8.2 → 1.9.1

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.
Files changed (176) hide show
  1. package/.agent/agents/ai-architect.md +39 -0
  2. package/.agent/agents/ai-asset-factory.md +700 -0
  3. package/.agent/agents/ai-audio-factory.md +503 -0
  4. package/.agent/agents/cloud-engineer.md +39 -0
  5. package/.agent/agents/game-developer.md +190 -89
  6. package/.agent/agents/marketing-specialist.md +41 -0
  7. package/.agent/agents/orchestrator.md +113 -3
  8. package/.agent/agents/penetration-tester.md +15 -1
  9. package/.agent/agents/project-planner.md +67 -0
  10. package/.agent/agents/unity-mobile-master.md +949 -0
  11. package/.agent/mcp/config/registry.json +65 -51
  12. package/.agent/mcp/servers/notebooklm/README.md +114 -0
  13. package/.agent/mcp/servers/notebooklm/package.json +35 -0
  14. package/.agent/mcp/servers/notebooklm/src/auth/chrome.ts +225 -0
  15. package/.agent/mcp/servers/notebooklm/src/auth/index.ts +1 -0
  16. package/.agent/mcp/servers/notebooklm/src/index.ts +516 -0
  17. package/.agent/mcp/servers/notebooklm/src/services/index.ts +3 -0
  18. package/.agent/mcp/servers/notebooklm/src/services/library.ts +217 -0
  19. package/.agent/mcp/servers/notebooklm/src/services/notebooklm.ts +380 -0
  20. package/.agent/mcp/servers/notebooklm/tsconfig.json +15 -0
  21. package/.agent/mcp-gateway/README.md +169 -20
  22. package/.agent/mcp-gateway/package.json +22 -7
  23. package/.agent/mcp-gateway/src/auth/index.ts +55 -0
  24. package/.agent/mcp-gateway/src/auth/middleware.ts +242 -0
  25. package/.agent/mcp-gateway/src/auth/oauth.ts +462 -0
  26. package/.agent/mcp-gateway/src/auth/scopes.ts +227 -0
  27. package/.agent/mcp-gateway/src/index.ts +252 -105
  28. package/.agent/mcp-gateway/src/observability/index.ts +5 -0
  29. package/.agent/mcp-gateway/src/observability/otel.ts +405 -0
  30. package/.agent/mcp-gateway/src/transports/index.ts +5 -0
  31. package/.agent/mcp-gateway/src/transports/streamableHttp.ts +235 -0
  32. package/.agent/rules/CODEX.md +115 -2
  33. package/.agent/rules/CODE_RULES.md +73 -0
  34. package/.agent/rules/GEMINI.md +26 -1
  35. package/.agent/rules/MEMORY_STATE.md +110 -0
  36. package/.agent/rules/REFERENCE.md +40 -58
  37. package/.agent/rules/REF_SKILLS.md +116 -0
  38. package/.agent/rules/REF_WORKFLOWS.md +81 -0
  39. package/.agent/scripts/ak_cli.py +106 -5
  40. package/.agent/scripts/memory_manager.py +48 -9
  41. package/.agent/skills/3d-web-experience/SKILL.md +386 -0
  42. package/.agent/skills/DEPENDENCIES.md +54 -0
  43. package/.agent/skills/ab-test-setup/SKILL.md +77 -0
  44. package/.agent/skills/active-directory-attacks/SKILL.md +59 -0
  45. package/.agent/skills/agent-evaluation/SKILL.md +430 -0
  46. package/.agent/skills/agent-memory-systems/SKILL.md +426 -0
  47. package/.agent/skills/agent-tool-builder/SKILL.md +139 -0
  48. package/.agent/skills/ai-agents-architect/SKILL.md +115 -0
  49. package/.agent/skills/ai-product/SKILL.md +86 -0
  50. package/.agent/skills/ai-wrapper-product/SKILL.md +90 -0
  51. package/.agent/skills/analytics-tracking/SKILL.md +88 -0
  52. package/.agent/skills/anti-hallucination/SKILL.md +295 -0
  53. package/.agent/skills/anti-hallucination/scripts/check_hallucination.py +299 -0
  54. package/.agent/skills/api-fuzzing-bug-bounty/SKILL.md +66 -0
  55. package/.agent/skills/app-store-optimization/SKILL.md +66 -0
  56. package/.agent/skills/autonomous-agent-patterns/SKILL.md +414 -0
  57. package/.agent/skills/aws-penetration-testing/SKILL.md +50 -0
  58. package/.agent/skills/aws-serverless/SKILL.md +327 -0
  59. package/.agent/skills/azure-functions/SKILL.md +340 -0
  60. package/.agent/skills/bifurcation-analysis/SKILL.md +56 -0
  61. package/.agent/skills/brainstorming/SKILL.md +80 -6
  62. package/.agent/skills/broken-authentication/SKILL.md +53 -0
  63. package/.agent/skills/browser-automation/SKILL.md +408 -0
  64. package/.agent/skills/browser-extension-builder/SKILL.md +422 -0
  65. package/.agent/skills/bullmq-specialist/SKILL.md +424 -0
  66. package/.agent/skills/bun-development/SKILL.md +386 -0
  67. package/.agent/skills/burp-suite-testing/SKILL.md +60 -0
  68. package/.agent/skills/clerk-auth/SKILL.md +432 -0
  69. package/.agent/skills/cloud-penetration-testing/SKILL.md +51 -0
  70. package/.agent/skills/copywriting/SKILL.md +66 -0
  71. package/.agent/skills/crewai/SKILL.md +470 -0
  72. package/.agent/skills/decision-memory/SKILL.md +317 -0
  73. package/.agent/skills/discord-bot-architect/SKILL.md +447 -0
  74. package/.agent/skills/email-sequence/SKILL.md +73 -0
  75. package/.agent/skills/emergence-detector/SKILL.md +230 -0
  76. package/.agent/skills/emergence-detector/scripts/check_emergence.py +265 -0
  77. package/.agent/skills/ethical-hacking-methodology/SKILL.md +67 -0
  78. package/.agent/skills/explained-qa/SKILL.md +142 -0
  79. package/.agent/skills/explained-qa/game-terminology.md +214 -0
  80. package/.agent/skills/firebase/SKILL.md +377 -0
  81. package/.agent/skills/game-development/ai-dialogue-engine/SKILL.md +442 -0
  82. package/.agent/skills/game-development/ai-graphics-generator/SKILL.md +463 -0
  83. package/.agent/skills/game-development/ai-playtest-framework/SKILL.md +570 -0
  84. package/.agent/skills/game-development/camera-systems/SKILL.md +607 -0
  85. package/.agent/skills/game-development/card-battle-engine/SKILL.md +618 -0
  86. package/.agent/skills/game-development/character-controller-3d/SKILL.md +908 -0
  87. package/.agent/skills/game-development/cloud-save-sync/SKILL.md +527 -0
  88. package/.agent/skills/game-development/combat-system/SKILL.md +748 -0
  89. package/.agent/skills/game-development/compliance-rating/SKILL.md +277 -0
  90. package/.agent/skills/game-development/crossplatform-build/SKILL.md +386 -0
  91. package/.agent/skills/game-development/cultivation-progression/SKILL.md +520 -0
  92. package/.agent/skills/game-development/data-driven-balance/SKILL.md +535 -0
  93. package/.agent/skills/game-development/game-analytics-integrator/SKILL.md +410 -0
  94. package/.agent/skills/game-development/game-audio-advanced/SKILL.md +646 -0
  95. package/.agent/skills/game-development/game-economy-designer/SKILL.md +375 -0
  96. package/.agent/skills/game-development/game-marketing/SKILL.md +85 -0
  97. package/.agent/skills/game-development/game-state-manager/SKILL.md +883 -0
  98. package/.agent/skills/game-development/godot-expert/SKILL.md +462 -0
  99. package/.agent/skills/game-development/hybrid-game-spec/SKILL.md +220 -0
  100. package/.agent/skills/game-development/inventory-quest/SKILL.md +747 -0
  101. package/.agent/skills/game-development/liveops/SKILL.md +308 -0
  102. package/.agent/skills/game-development/localization/SKILL.md +286 -0
  103. package/.agent/skills/game-development/mobile-input-patterns/SKILL.md +343 -0
  104. package/.agent/skills/game-development/monetization-strategy/SKILL.md +94 -0
  105. package/.agent/skills/game-development/multiplayer-master/SKILL.md +727 -0
  106. package/.agent/skills/game-development/narrative-branching/SKILL.md +593 -0
  107. package/.agent/skills/game-development/npc-ai-integration/SKILL.md +110 -0
  108. package/.agent/skills/game-development/procedural-generation/SKILL.md +168 -0
  109. package/.agent/skills/game-development/procedural-level-ai/SKILL.md +367 -0
  110. package/.agent/skills/game-development/prototyping-rapid/SKILL.md +205 -0
  111. package/.agent/skills/game-development/spec-ecosystem/SKILL.md +155 -0
  112. package/.agent/skills/game-development/spec-ecosystem/decision-log-format.md +129 -0
  113. package/.agent/skills/game-development/spec-ecosystem/templates/PLAN-template.md +178 -0
  114. package/.agent/skills/game-development/spec-ecosystem/templates/SPEC-template.md +110 -0
  115. package/.agent/skills/game-development/spec-ecosystem/templates/TASKS-template.md +156 -0
  116. package/.agent/skills/game-development/survival-systems/SKILL.md +493 -0
  117. package/.agent/skills/game-development/testing-qa/SKILL.md +270 -0
  118. package/.agent/skills/game-development/unity-integration/SKILL.md +358 -0
  119. package/.agent/skills/game-development/unity-mobile-optimization/SKILL.md +271 -0
  120. package/.agent/skills/game-development/webgpu-shading/SKILL.md +209 -0
  121. package/.agent/skills/gcp-cloud-run/SKILL.md +358 -0
  122. package/.agent/skills/graphql/SKILL.md +492 -0
  123. package/.agent/skills/idor-testing/SKILL.md +64 -0
  124. package/.agent/skills/inngest/SKILL.md +128 -0
  125. package/.agent/skills/intent-capture/SKILL.md +65 -0
  126. package/.agent/skills/langfuse/SKILL.md +415 -0
  127. package/.agent/skills/langgraph/SKILL.md +360 -0
  128. package/.agent/skills/launch-strategy/SKILL.md +68 -0
  129. package/.agent/skills/linux-privilege-escalation/SKILL.md +62 -0
  130. package/.agent/skills/llm-app-patterns/SKILL.md +367 -0
  131. package/.agent/skills/marketing-ideas/SKILL.md +66 -0
  132. package/.agent/skills/mcp-composition/SKILL.md +362 -0
  133. package/.agent/skills/mcp-observability/SKILL.md +323 -0
  134. package/.agent/skills/mcp-security/SKILL.md +314 -0
  135. package/.agent/skills/metasploit-framework/SKILL.md +60 -0
  136. package/.agent/skills/micro-saas-launcher/SKILL.md +93 -0
  137. package/.agent/skills/neon-postgres/SKILL.md +339 -0
  138. package/.agent/skills/paid-ads/SKILL.md +64 -0
  139. package/.agent/skills/supabase-integration/SKILL.md +411 -0
  140. package/.agent/skills/trust-spectrum/SKILL.md +291 -0
  141. package/.agent/skills/vibe-coding-guard/SKILL.md +328 -0
  142. package/.agent/templates/AGENTS.game.md +63 -0
  143. package/.agent/templates/docs/WORKFLOW_GUIDE.en.md +100 -0
  144. package/.agent/templates/docs/WORKFLOW_GUIDE.vi.md +100 -0
  145. package/.agent/workflows/ai-agent.md +38 -0
  146. package/.agent/workflows/autofix.md +1 -0
  147. package/.agent/workflows/brainstorm.md +1 -0
  148. package/.agent/workflows/context.md +1 -0
  149. package/.agent/workflows/create.md +39 -8
  150. package/.agent/workflows/dashboard.md +1 -0
  151. package/.agent/workflows/debug.md +14 -0
  152. package/.agent/workflows/deploy.md +14 -0
  153. package/.agent/workflows/enhance.md +44 -0
  154. package/.agent/workflows/gamekit-init.md +177 -0
  155. package/.agent/workflows/gamekit-launch.md +338 -0
  156. package/.agent/workflows/gamekit-plan.md +204 -0
  157. package/.agent/workflows/gamekit-qa.md +153 -0
  158. package/.agent/workflows/gamekit-spec.md +243 -0
  159. package/.agent/workflows/gamekit-tasks.md +208 -0
  160. package/.agent/workflows/marketing.md +39 -0
  161. package/.agent/workflows/next.md +1 -0
  162. package/.agent/workflows/orchestrate.md +12 -0
  163. package/.agent/workflows/pentest.md +39 -0
  164. package/.agent/workflows/plan.md +42 -0
  165. package/.agent/workflows/preview.md +1 -0
  166. package/.agent/workflows/quality.md +1 -0
  167. package/.agent/workflows/saas.md +38 -0
  168. package/.agent/workflows/spec.md +42 -0
  169. package/.agent/workflows/status.md +1 -0
  170. package/.agent/workflows/test.md +14 -0
  171. package/.agent/workflows/ui-ux-pro-max.md +1 -0
  172. package/README.md +4 -4
  173. package/bin/cli.js +411 -111
  174. package/package.json +1 -2
  175. package/docs/AI_DATA_INFRASTRUCTURE.md +0 -288
  176. package/docs/CHANGELOG_AI_INFRA.md +0 -111
@@ -1,9 +1,14 @@
1
1
  #!/usr/bin/env node
2
2
  /**
3
- * Agent Kit MCP Gateway Server
3
+ * Agent Kit MCP Gateway Server v2.0
4
4
  *
5
- * Provides AI agents with live access to project context, dependency graphs,
6
- * and semantic search with automatic sync capabilities.
5
+ * Enhanced MCP server with:
6
+ * - Dual transport (stdio + Streamable HTTP)
7
+ * - OAuth 2.1 / API Key authentication
8
+ * - OpenTelemetry observability
9
+ * - Semantic search with auto-sync
10
+ *
11
+ * @version 2.0.0
7
12
  */
8
13
 
9
14
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
@@ -12,17 +17,42 @@ import { z } from "zod";
12
17
  import * as fs from "fs";
13
18
  import * as path from "path";
14
19
 
15
- // Import sync modules
20
+ // Import modules
16
21
  import { IncrementalSyncer, getGlobalDebouncer, TimestampChecker } from "./sync/index.js";
22
+ import { createStreamableHttpTransport, type StreamableHttpOptions } from "./transports/index.js";
23
+ import { createApiKey, validateApiKey, extractApiKey, type AuthResult } from "./auth/index.js";
24
+ import { traceToolCall, getMetrics, initializeTracing } from "./observability/index.js";
25
+
26
+ // ============================================================================
27
+ // Configuration
28
+ // ============================================================================
17
29
 
18
- // Get project root from environment or command line
19
30
  const PROJECT_ROOT = process.env.PROJECT_ROOT || process.cwd();
31
+ const HTTP_PORT = parseInt(process.env.MCP_HTTP_PORT || "3100", 10);
32
+ const ENABLE_HTTP = process.env.MCP_ENABLE_HTTP === "true";
33
+ const ENABLE_AUTH = process.env.MCP_ENABLE_AUTH === "true";
34
+ const API_KEY = process.env.MCP_API_KEY;
35
+
36
+ // ============================================================================
37
+ // Initialize Components
38
+ // ============================================================================
20
39
 
21
- // Initialize sync components
22
40
  const syncer = new IncrementalSyncer(PROJECT_ROOT);
23
- const debouncer = getGlobalDebouncer(30000); // 30 second cooldown
41
+ const debouncer = getGlobalDebouncer(30000);
24
42
  const timestampChecker = new TimestampChecker(PROJECT_ROOT);
25
43
 
44
+ // Initialize tracing
45
+ initializeTracing({
46
+ serviceName: "agent-kit-mcp",
47
+ serviceVersion: "2.0.0",
48
+ });
49
+
50
+ // Create default API key if provided via env
51
+ if (API_KEY) {
52
+ createApiKey("default", ["read:project", "read:graph", "read:search", "write:sync"]);
53
+ console.error(`[MCP] API key configured from environment`);
54
+ }
55
+
26
56
  // ============================================================================
27
57
  // Auto-Sync Helper
28
58
  // ============================================================================
@@ -70,7 +100,7 @@ function readTextFile(filePath: string): string | null {
70
100
 
71
101
  const server = new McpServer({
72
102
  name: "agent-kit-gateway",
73
- version: "1.1.0", // Universal Intelligence Version
103
+ version: "2.0.0",
74
104
  });
75
105
 
76
106
  // ============================================================================
@@ -84,38 +114,40 @@ server.tool(
84
114
  section: z.enum(["all", "tech_stack", "structure", "conventions", "commands"]).optional().default("all")
85
115
  },
86
116
  async ({ section }) => {
87
- const agentsMd = readTextFile("AGENTS.md");
88
- if (!agentsMd) {
89
- return {
90
- content: [{ type: "text" as const, text: "AGENTS.md not found. Run 'ak init' first." }]
91
- };
92
- }
93
-
94
- const sections: Record<string, string> = {};
95
- const lines = agentsMd.split("\n");
96
- let currentSection = "";
97
- let currentContent: string[] = [];
98
-
99
- for (const line of lines) {
100
- if (line.startsWith("## ")) {
101
- if (currentSection) sections[currentSection] = currentContent.join("\n").trim();
102
- currentSection = line.replace("## ", "").trim();
103
- currentContent = [];
104
- } else {
105
- currentContent.push(line);
117
+ return traceToolCall("get_project_context", { section }, async () => {
118
+ const agentsMd = readTextFile("AGENTS.md");
119
+ if (!agentsMd) {
120
+ return {
121
+ content: [{ type: "text" as const, text: "AGENTS.md not found. Run 'ak init' first." }]
122
+ };
106
123
  }
107
- }
108
- if (currentSection) sections[currentSection] = currentContent.join("\n").trim();
109
-
110
- const sectionMap: Record<string, string | undefined> = {
111
- tech_stack: sections["🛠️ Tech Stack"] || sections["Tech Stack"],
112
- structure: sections["📁 Directory Map"] || sections["Directory Map"],
113
- conventions: sections["📜 Rules & Conventions"] || sections["Rules & Conventions"],
114
- commands: sections["🔧 Commands Reference"] || sections["Commands Reference"],
115
- all: agentsMd,
116
- };
117
124
 
118
- return { content: [{ type: "text" as const, text: sectionMap[section] || agentsMd }] };
125
+ const sections: Record<string, string> = {};
126
+ const lines = agentsMd.split("\n");
127
+ let currentSection = "";
128
+ let currentContent: string[] = [];
129
+
130
+ for (const line of lines) {
131
+ if (line.startsWith("## ")) {
132
+ if (currentSection) sections[currentSection] = currentContent.join("\n").trim();
133
+ currentSection = line.replace("## ", "").trim();
134
+ currentContent = [];
135
+ } else {
136
+ currentContent.push(line);
137
+ }
138
+ }
139
+ if (currentSection) sections[currentSection] = currentContent.join("\n").trim();
140
+
141
+ const sectionMap: Record<string, string | undefined> = {
142
+ tech_stack: sections["🛠️ Tech Stack"] || sections["Tech Stack"],
143
+ structure: sections["📁 Directory Map"] || sections["Directory Map"],
144
+ conventions: sections["📜 Rules & Conventions"] || sections["Rules & Conventions"],
145
+ commands: sections["🔧 Commands Reference"] || sections["Commands Reference"],
146
+ all: agentsMd,
147
+ };
148
+
149
+ return { content: [{ type: "text" as const, text: sectionMap[section] || agentsMd }] };
150
+ });
119
151
  }
120
152
  );
121
153
 
@@ -128,22 +160,24 @@ server.tool(
128
160
  "Get high-level project summary: Code vs Docs distribution, primary types, and impact analysis.",
129
161
  {},
130
162
  async () => {
131
- const graph = readJsonFile(".agent/graph.json");
132
- if (!graph) return { content: [{ type: "text" as const, text: "Project data not generated." }] };
133
-
134
- const stats = graph.metadata?.file_types || {};
135
- const total = graph.metadata?.total_files || 1;
136
- const docCount = (stats.documentation || 0) + (stats.document || 0) + (stats.readme || 0);
137
- const codeCount = (stats.component || 0) + (stats.module || 0) + (stats.utility || 0);
138
-
139
- const intelligence = {
140
- project_name: path.basename(PROJECT_ROOT),
141
- project_type: docCount > codeCount ? "Documentation-Heavy" : "Code-Centric",
142
- distribution: { docs: `${Math.round((docCount / total) * 100)}%`, code: `${Math.round((codeCount / total) * 100)}%` },
143
- top_files: graph.nodes?.slice(0, 5).map((n: any) => n.id)
144
- };
163
+ return traceToolCall("get_project_intelligence", {}, async () => {
164
+ const graph = readJsonFile(".agent/graph.json");
165
+ if (!graph) return { content: [{ type: "text" as const, text: "Project data not generated." }] };
166
+
167
+ const stats = graph.metadata?.file_types || {};
168
+ const total = graph.metadata?.total_files || 1;
169
+ const docCount = (stats.documentation || 0) + (stats.document || 0) + (stats.readme || 0);
170
+ const codeCount = (stats.component || 0) + (stats.module || 0) + (stats.utility || 0);
171
+
172
+ const intelligence = {
173
+ project_name: path.basename(PROJECT_ROOT),
174
+ project_type: docCount > codeCount ? "Documentation-Heavy" : "Code-Centric",
175
+ distribution: { docs: `${Math.round((docCount / total) * 100)}%`, code: `${Math.round((codeCount / total) * 100)}%` },
176
+ top_files: graph.nodes?.slice(0, 5).map((n: any) => n.id)
177
+ };
145
178
 
146
- return { content: [{ type: "text" as const, text: JSON.stringify(intelligence, null, 2) }] };
179
+ return { content: [{ type: "text" as const, text: JSON.stringify(intelligence, null, 2) }] };
180
+ });
147
181
  }
148
182
  );
149
183
 
@@ -159,25 +193,27 @@ server.tool(
159
193
  direction: z.enum(["imports", "imported_by", "both"]).optional().default("both")
160
194
  },
161
195
  async ({ file_path, direction }) => {
162
- await autoSyncIfNeeded();
163
- const graph = readJsonFile(".agent/graph.json");
164
- if (!graph) return { content: [{ type: "text" as const, text: "Graph not found." }] };
165
-
166
- const normalizedPath = file_path.replace(/^\.\//, "");
167
- const node = graph.nodes?.find((n: any) => n.id === normalizedPath);
168
- if (!node) return { content: [{ type: "text" as const, text: "File not found in graph." }] };
169
-
170
- const isDoc = ["documentation", "readme", "document"].includes(node.type);
171
- const outLabel = isDoc ? "references" : "imports";
172
- const inLabel = isDoc ? "referenced_by" : "imported_by";
173
-
174
- const result: any = { file: normalizedPath, type: node.type };
175
- if (direction !== "imported_by") result[outLabel] = node.imports || [];
176
- if (direction !== "imports") {
177
- result[inLabel] = graph.edges?.filter((e: any) => e.target === normalizedPath).map((e: any) => e.source) || [];
178
- }
196
+ return traceToolCall("analyze_dependencies", { file_path, direction }, async () => {
197
+ await autoSyncIfNeeded();
198
+ const graph = readJsonFile(".agent/graph.json");
199
+ if (!graph) return { content: [{ type: "text" as const, text: "Graph not found." }] };
200
+
201
+ const normalizedPath = file_path.replace(/^\.\//, "");
202
+ const node = graph.nodes?.find((n: any) => n.id === normalizedPath);
203
+ if (!node) return { content: [{ type: "text" as const, text: "File not found in graph." }] };
204
+
205
+ const isDoc = ["documentation", "readme", "document"].includes(node.type);
206
+ const outLabel = isDoc ? "references" : "imports";
207
+ const inLabel = isDoc ? "referenced_by" : "imported_by";
208
+
209
+ const result: any = { file: normalizedPath, type: node.type };
210
+ if (direction !== "imported_by") result[outLabel] = node.imports || [];
211
+ if (direction !== "imports") {
212
+ result[inLabel] = graph.edges?.filter((e: any) => e.target === normalizedPath).map((e: any) => e.source) || [];
213
+ }
179
214
 
180
- return { content: [{ type: "text" as const, text: JSON.stringify(result, null, 2) }] };
215
+ return { content: [{ type: "text" as const, text: JSON.stringify(result, null, 2) }] };
216
+ });
181
217
  }
182
218
  );
183
219
 
@@ -186,29 +222,31 @@ server.tool(
186
222
  // ============================================================================
187
223
 
188
224
  async function handleSearch(args: { query: string, file_filter?: string, top_k: number }) {
189
- await autoSyncIfNeeded();
190
- const chunks = readJsonFile(".agent/rag/chunks.json");
191
- if (!chunks?.chunks) return { content: [{ type: "text" as const, text: "No chunks found." }] };
192
-
193
- const query = args.query.toLowerCase();
194
- const results = chunks.chunks
195
- .map((chunk: any) => {
196
- let score = 0;
197
- const content = chunk.content.toLowerCase();
198
- if (content.includes(query)) score += 5;
199
- if (chunk.metadata.name?.toLowerCase().includes(query)) score += 10;
200
- return { chunk, score };
201
- })
202
- .filter((s: any) => s.score > 0)
203
- .sort((a: any, b: any) => b.score - a.score)
204
- .slice(0, args.top_k)
205
- .map((s: any) => ({
206
- file: s.chunk.metadata.file_path,
207
- context: s.chunk.metadata.context_path || s.chunk.metadata.name,
208
- preview: s.chunk.content.substring(0, 250) + "..."
209
- }));
210
-
211
- return { content: [{ type: "text" as const, text: JSON.stringify(results, null, 2) }] };
225
+ return traceToolCall("search_knowledge", args, async () => {
226
+ await autoSyncIfNeeded();
227
+ const chunks = readJsonFile(".agent/rag/chunks.json");
228
+ if (!chunks?.chunks) return { content: [{ type: "text" as const, text: "No chunks found." }] };
229
+
230
+ const query = args.query.toLowerCase();
231
+ const results = chunks.chunks
232
+ .map((chunk: any) => {
233
+ let score = 0;
234
+ const content = chunk.content.toLowerCase();
235
+ if (content.includes(query)) score += 5;
236
+ if (chunk.metadata.name?.toLowerCase().includes(query)) score += 10;
237
+ return { chunk, score };
238
+ })
239
+ .filter((s: any) => s.score > 0)
240
+ .sort((a: any, b: any) => b.score - a.score)
241
+ .slice(0, args.top_k)
242
+ .map((s: any) => ({
243
+ file: s.chunk.metadata.file_path,
244
+ context: s.chunk.metadata.context_path || s.chunk.metadata.name,
245
+ preview: s.chunk.content.substring(0, 250) + "..."
246
+ }));
247
+
248
+ return { content: [{ type: "text" as const, text: JSON.stringify(results, null, 2) }] };
249
+ });
212
250
  }
213
251
 
214
252
  server.tool(
@@ -242,16 +280,104 @@ server.tool(
242
280
  "Find files affected by changing a file.",
243
281
  { file_path: z.string() },
244
282
  async ({ file_path }) => {
245
- await autoSyncIfNeeded();
246
- const graph = readJsonFile(".agent/graph.json");
247
- if (!graph) return { content: [{ type: "text" as const, text: "Graph not found." }] };
283
+ return traceToolCall("get_impact_zone", { file_path }, async () => {
284
+ await autoSyncIfNeeded();
285
+ const graph = readJsonFile(".agent/graph.json");
286
+ if (!graph) return { content: [{ type: "text" as const, text: "Graph not found." }] };
287
+
288
+ const normalizedPath = file_path.replace(/^\.\//, "");
289
+ const affected = graph.edges
290
+ ?.filter((e: any) => e.target === normalizedPath)
291
+ .map((e: any) => e.source) || [];
292
+
293
+ return { content: [{ type: "text" as const, text: JSON.stringify({ file: normalizedPath, affected }, null, 2) }] };
294
+ });
295
+ }
296
+ );
248
297
 
249
- const normalizedPath = file_path.replace(/^\.\//, "");
250
- const affected = graph.edges
251
- ?.filter((e: any) => e.target === normalizedPath)
252
- .map((e: any) => e.source) || [];
298
+ // ============================================================================
299
+ // Tool: force_sync (NEW)
300
+ // ============================================================================
253
301
 
254
- return { content: [{ type: "text" as const, text: JSON.stringify({ file: normalizedPath, affected }, null, 2) }] };
302
+ server.tool(
303
+ "force_sync",
304
+ "Force refresh all AI data (graph, chunks, AGENTS.md)",
305
+ {
306
+ target: z.enum(["all", "graph", "rag", "agents_md"]).optional().default("all")
307
+ },
308
+ async ({ target }) => {
309
+ return traceToolCall("force_sync", { target }, async () => {
310
+ const result = await syncer.syncAll();
311
+ return {
312
+ content: [{
313
+ type: "text" as const,
314
+ text: JSON.stringify({
315
+ success: true,
316
+ target,
317
+ ...result
318
+ }, null, 2)
319
+ }]
320
+ };
321
+ });
322
+ }
323
+ );
324
+
325
+ // ============================================================================
326
+ // Tool: get_metrics (NEW - Observability)
327
+ // ============================================================================
328
+
329
+ server.tool(
330
+ "get_metrics",
331
+ "Get MCP server performance metrics",
332
+ {},
333
+ async () => {
334
+ return traceToolCall("get_metrics", {}, async () => {
335
+ const metrics = getMetrics();
336
+ return {
337
+ content: [{
338
+ type: "text" as const,
339
+ text: JSON.stringify(metrics, null, 2)
340
+ }]
341
+ };
342
+ });
343
+ }
344
+ );
345
+
346
+ // ============================================================================
347
+ // Tool: get_server_info (NEW)
348
+ // ============================================================================
349
+
350
+ server.tool(
351
+ "get_server_info",
352
+ "Get MCP server information and capabilities",
353
+ {},
354
+ async () => {
355
+ return {
356
+ content: [{
357
+ type: "text" as const,
358
+ text: JSON.stringify({
359
+ name: "agent-kit-gateway",
360
+ version: "2.0.0",
361
+ features: {
362
+ transport: ENABLE_HTTP ? ["stdio", "streamable-http"] : ["stdio"],
363
+ auth: ENABLE_AUTH ? ["api-key", "oauth2.1"] : ["none"],
364
+ observability: ["opentelemetry", "metrics"],
365
+ },
366
+ tools: [
367
+ "get_project_context",
368
+ "get_project_intelligence",
369
+ "analyze_dependencies",
370
+ "search_knowledge",
371
+ "search_code_logic",
372
+ "get_impact_zone",
373
+ "force_sync",
374
+ "get_metrics",
375
+ "get_server_info",
376
+ ],
377
+ project_root: PROJECT_ROOT,
378
+ }, null, 2)
379
+ }]
380
+ };
255
381
  }
256
382
  );
257
383
 
@@ -260,11 +386,32 @@ server.tool(
260
386
  // ============================================================================
261
387
 
262
388
  async function main() {
263
- const transport = new StdioServerTransport();
264
- await server.connect(transport);
389
+ console.error("[MCP] Agent Kit Gateway v2.0.0 starting...");
390
+ console.error(`[MCP] Project root: ${PROJECT_ROOT}`);
391
+
392
+ // Start stdio transport (always)
393
+ const stdioTransport = new StdioServerTransport();
394
+ await server.connect(stdioTransport);
395
+ console.error("[MCP] stdio transport connected");
396
+
397
+ // Optionally start HTTP transport
398
+ if (ENABLE_HTTP) {
399
+ const httpOptions: StreamableHttpOptions = {
400
+ port: HTTP_PORT,
401
+ enableSSE: true,
402
+ stateless: true,
403
+ enableAuth: ENABLE_AUTH,
404
+ corsOrigins: process.env.MCP_CORS_ORIGINS?.split(",") || [],
405
+ };
406
+
407
+ await createStreamableHttpTransport(httpOptions);
408
+ console.error(`[MCP] Streamable HTTP transport available on port ${HTTP_PORT}`);
409
+ }
410
+
411
+ console.error("[MCP] Gateway ready!");
265
412
  }
266
413
 
267
414
  main().catch(err => {
268
- console.error(err);
415
+ console.error("[MCP] Fatal error:", err);
269
416
  process.exit(1);
270
417
  });
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Observability module exports
3
+ */
4
+
5
+ export * from "./otel.js";