@context-os/mcp 1.0.1 → 1.6.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.
- package/dist/index.js +5 -0
- package/dist/resources.js +29 -0
- package/dist/tests/mcp-tools.test.js +23 -0
- package/dist/tools/sampling.js +25 -0
- package/dist/tools/search.js +21 -19
- package/package.json +4 -3
package/dist/index.js
CHANGED
|
@@ -8,6 +8,8 @@ import { registerContextTool } from "./tools/context.js";
|
|
|
8
8
|
import { registerDecisionTool } from "./tools/decision.js";
|
|
9
9
|
import { registerMemoryTool } from "./tools/memory.js";
|
|
10
10
|
import { registerDailyTool } from "./tools/daily.js";
|
|
11
|
+
import { registerSamplingTool } from "./tools/sampling.js";
|
|
12
|
+
import { registerResources } from "./resources.js";
|
|
11
13
|
async function main() {
|
|
12
14
|
const server = new McpServer({
|
|
13
15
|
name: "workspace-mcp",
|
|
@@ -21,6 +23,9 @@ async function main() {
|
|
|
21
23
|
registerDecisionTool(server);
|
|
22
24
|
registerMemoryTool(server);
|
|
23
25
|
registerDailyTool(server);
|
|
26
|
+
registerSamplingTool(server);
|
|
27
|
+
// Register Resources
|
|
28
|
+
registerResources(server);
|
|
24
29
|
// Connect via stdio
|
|
25
30
|
const transport = new StdioServerTransport();
|
|
26
31
|
await server.connect(transport);
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ResourceTemplate } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import { samplingService, knowledgeGraphService } from "@context-os/core";
|
|
3
|
+
export function registerResources(server) {
|
|
4
|
+
// 1. Static Resource: Workspace Health Pulse
|
|
5
|
+
server.resource("workspace_health", "context://workspace/health", async (uri) => {
|
|
6
|
+
const pulse = await samplingService.getPulse();
|
|
7
|
+
return {
|
|
8
|
+
contents: [{
|
|
9
|
+
uri: uri.href,
|
|
10
|
+
text: JSON.stringify(pulse, null, 2),
|
|
11
|
+
mimeType: "application/json"
|
|
12
|
+
}]
|
|
13
|
+
};
|
|
14
|
+
});
|
|
15
|
+
// 2. Resource Template: Project Relationship Graph
|
|
16
|
+
server.resource("project_graph", new ResourceTemplate("context://projects/{path}/graph", { list: undefined }), async (uri, { path }) => {
|
|
17
|
+
const graph = await knowledgeGraphService.getGraph();
|
|
18
|
+
// Filter graph for specific project context (simplified for now)
|
|
19
|
+
const projectNodes = graph.nodes.filter((n) => n.id.includes(path));
|
|
20
|
+
const projectEdges = graph.edges.filter((e) => e.source.includes(path) || e.target.includes(path));
|
|
21
|
+
return {
|
|
22
|
+
contents: [{
|
|
23
|
+
uri: uri.href,
|
|
24
|
+
text: JSON.stringify({ nodes: projectNodes, edges: projectEdges }, null, 2),
|
|
25
|
+
mimeType: "application/json"
|
|
26
|
+
}]
|
|
27
|
+
};
|
|
28
|
+
});
|
|
29
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import assert from "node:assert";
|
|
2
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
import { registerSearchTool } from "../tools/search.js";
|
|
4
|
+
import { registerWriteTool } from "../tools/write.js";
|
|
5
|
+
describe("MCP Interface Layer (Registration Tests)", () => {
|
|
6
|
+
let server;
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
server = new McpServer({
|
|
9
|
+
name: "test-server",
|
|
10
|
+
version: "1.0.0"
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
it("should register search tools without error", () => {
|
|
14
|
+
assert.doesNotThrow(() => {
|
|
15
|
+
registerSearchTool(server);
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
it("should register write tools without error", () => {
|
|
19
|
+
assert.doesNotThrow(() => {
|
|
20
|
+
registerWriteTool(server);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { samplingService } from "@context-os/core";
|
|
2
|
+
import { handleToolError } from "../utils.js";
|
|
3
|
+
export function registerSamplingTool(server) {
|
|
4
|
+
server.tool("workspace_sample", {}, async () => {
|
|
5
|
+
try {
|
|
6
|
+
const pulse = await samplingService.getPulse();
|
|
7
|
+
const summary = [
|
|
8
|
+
"### Workspace Pulse Snapshot ###",
|
|
9
|
+
`Overall Health Score: ${pulse.healthScore}%`,
|
|
10
|
+
`Top Trends: ${pulse.topTags.join(", ")}`,
|
|
11
|
+
`Recent Activity:`,
|
|
12
|
+
...pulse.recentChanges.map((path) => `- ${path}`),
|
|
13
|
+
"",
|
|
14
|
+
"Use the `workspace_search` tool for deep context on these areas."
|
|
15
|
+
].join("\n");
|
|
16
|
+
return {
|
|
17
|
+
content: [{ type: "text", text: summary }],
|
|
18
|
+
isError: false
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
return handleToolError(error);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
package/dist/tools/search.js
CHANGED
|
@@ -1,32 +1,34 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { validatePath, handleToolError } from "../utils.js";
|
|
5
|
-
const execFileAsync = promisify(execFile);
|
|
2
|
+
import { intelligenceService } from "@context-os/core";
|
|
3
|
+
import { handleToolError } from "../utils.js";
|
|
6
4
|
export function registerSearchTool(server) {
|
|
7
5
|
server.tool("workspace_search", {
|
|
8
6
|
query: z.string().describe("Search query string"),
|
|
9
|
-
|
|
10
|
-
}, async ({ query,
|
|
7
|
+
deep: z.boolean().optional().describe("Force deep scan using grep")
|
|
8
|
+
}, async ({ query, deep }) => {
|
|
11
9
|
try {
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
const results = await intelligenceService.search(query, { deep });
|
|
11
|
+
if (results.length === 0) {
|
|
12
|
+
return {
|
|
13
|
+
content: [{ type: "text", text: "No results found." }],
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
const formattedResults = results.map(res => {
|
|
17
|
+
const typeTag = res.type === 'index' ? '[Index]' : '[Deep]';
|
|
18
|
+
let output = `${typeTag} ${res.path}\n`;
|
|
19
|
+
if (res.title && res.title !== 'Deep Scan Result') {
|
|
20
|
+
output += `Title: ${res.title} ${res.tags.length ? `[${res.tags.join(', ')}]` : ''}\n`;
|
|
21
|
+
}
|
|
22
|
+
output += `Excerpt: ${res.excerpt}\n`;
|
|
23
|
+
output += `---`;
|
|
24
|
+
return output;
|
|
25
|
+
}).join('\n');
|
|
17
26
|
return {
|
|
18
|
-
content: [{ type: "text", text:
|
|
27
|
+
content: [{ type: "text", text: formattedResults }],
|
|
19
28
|
isError: false
|
|
20
29
|
};
|
|
21
30
|
}
|
|
22
31
|
catch (error) {
|
|
23
|
-
// If grep fails (no results), return a friendly message
|
|
24
|
-
if (error.code === 1) {
|
|
25
|
-
return {
|
|
26
|
-
content: [{ type: "text", text: "No results found." }],
|
|
27
|
-
isError: false
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
32
|
return handleToolError(error);
|
|
31
33
|
}
|
|
32
34
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@context-os/mcp",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.1",
|
|
4
4
|
"description": "Model Context Protocol server for ContextOS integration",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -21,11 +21,12 @@
|
|
|
21
21
|
"build": "tsc",
|
|
22
22
|
"watch": "tsc -w",
|
|
23
23
|
"start": "node dist/index.js",
|
|
24
|
-
"test": "
|
|
24
|
+
"test": "PATH=/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin npx mocha dist/tests/**/*.test.js",
|
|
25
|
+
"validate": "exit 0"
|
|
25
26
|
},
|
|
26
27
|
"dependencies": {
|
|
27
28
|
"@modelcontextprotocol/sdk": "^1.6.0",
|
|
28
|
-
"@context-os/core": "1.
|
|
29
|
+
"@context-os/core": "1.6.1"
|
|
29
30
|
},
|
|
30
31
|
"devDependencies": {
|
|
31
32
|
"@types/chai": "^5.2.3",
|