@context-os/mcp 1.0.0 → 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/{workspace-mcp/src/index.js → 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 +35 -0
- package/package.json +4 -3
- package/dist/packages/core/src/index.js +0 -88
- package/dist/workspace-mcp/src/tools/search.js +0 -33
- /package/dist/{workspace-mcp/src/tests → tests}/isolation.test.js +0 -0
- /package/dist/{workspace-mcp/src/tools → tools}/context.js +0 -0
- /package/dist/{workspace-mcp/src/tools → tools}/daily.js +0 -0
- /package/dist/{workspace-mcp/src/tools → tools}/decision.js +0 -0
- /package/dist/{workspace-mcp/src/tools → tools}/memory.js +0 -0
- /package/dist/{workspace-mcp/src/tools → tools}/read.js +0 -0
- /package/dist/{workspace-mcp/src/tools → tools}/write.js +0 -0
- /package/dist/{workspace-mcp/src/utils.js → utils.js} +0 -0
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { intelligenceService } from "@context-os/core";
|
|
3
|
+
import { handleToolError } from "../utils.js";
|
|
4
|
+
export function registerSearchTool(server) {
|
|
5
|
+
server.tool("workspace_search", {
|
|
6
|
+
query: z.string().describe("Search query string"),
|
|
7
|
+
deep: z.boolean().optional().describe("Force deep scan using grep")
|
|
8
|
+
}, async ({ query, deep }) => {
|
|
9
|
+
try {
|
|
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');
|
|
26
|
+
return {
|
|
27
|
+
content: [{ type: "text", text: formattedResults }],
|
|
28
|
+
isError: false
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
return handleToolError(error);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
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",
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import fs from 'node:fs';
|
|
3
|
-
import { spawn } from 'node:child_process';
|
|
4
|
-
/**
|
|
5
|
-
* Discovers the workspace root by looking for root/soul.md in parent directories.
|
|
6
|
-
*/
|
|
7
|
-
export function findWorkspaceRoot() {
|
|
8
|
-
let current = process.cwd();
|
|
9
|
-
const root = path.parse(current).root;
|
|
10
|
-
while (current !== root) {
|
|
11
|
-
if (fs.existsSync(path.join(current, "root", "soul.md"))) {
|
|
12
|
-
return fs.realpathSync(current);
|
|
13
|
-
}
|
|
14
|
-
current = path.dirname(current);
|
|
15
|
-
}
|
|
16
|
-
return fs.realpathSync(process.cwd()); // Fallback to CWD
|
|
17
|
-
}
|
|
18
|
-
export const workspaceRoot = findWorkspaceRoot();
|
|
19
|
-
/**
|
|
20
|
-
* Standard ContextOS "Buckets" for security isolation.
|
|
21
|
-
*/
|
|
22
|
-
export const ALLOWED_BUCKETS = [
|
|
23
|
-
"projects",
|
|
24
|
-
"knowledge",
|
|
25
|
-
"schemas",
|
|
26
|
-
"archive",
|
|
27
|
-
"log",
|
|
28
|
-
"orgs",
|
|
29
|
-
"root"
|
|
30
|
-
];
|
|
31
|
-
/**
|
|
32
|
-
* Validates that a path is within the workspace root and inside an allowed bucket.
|
|
33
|
-
*/
|
|
34
|
-
export function validatePath(requestedPath) {
|
|
35
|
-
const resolvedPath = path.resolve(workspaceRoot, requestedPath);
|
|
36
|
-
let fullPath;
|
|
37
|
-
try {
|
|
38
|
-
fullPath = fs.realpathSync(resolvedPath);
|
|
39
|
-
}
|
|
40
|
-
catch (e) {
|
|
41
|
-
fullPath = resolvedPath;
|
|
42
|
-
}
|
|
43
|
-
const relativePath = path.relative(workspaceRoot, fullPath);
|
|
44
|
-
// Security check: must be within the workspace root
|
|
45
|
-
if (relativePath.startsWith("..") || path.isAbsolute(relativePath)) {
|
|
46
|
-
throw new Error(`Security violation: Path ${requestedPath} is outside the allowed ContextOS workspace root.`);
|
|
47
|
-
}
|
|
48
|
-
// Enterprise check: must be within an allowed bucket
|
|
49
|
-
const isAllowed = ALLOWED_BUCKETS.some(bucket => {
|
|
50
|
-
const bucketRoot = path.join(workspaceRoot, bucket);
|
|
51
|
-
const bucketRelative = path.relative(bucketRoot, fullPath);
|
|
52
|
-
return !bucketRelative.startsWith("..") && !path.isAbsolute(bucketRelative);
|
|
53
|
-
});
|
|
54
|
-
if (!isAllowed) {
|
|
55
|
-
throw new Error(`Security violation: Path ${requestedPath} is outside the allowed bucket (projects, orgs, knowledge, schemas, etc).`);
|
|
56
|
-
}
|
|
57
|
-
return { fullPath, relativePath };
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Checks if a path is in a read-only bucket for agents.
|
|
61
|
-
*/
|
|
62
|
-
export function isReadOnly(filePath) {
|
|
63
|
-
const { fullPath } = validatePath(filePath);
|
|
64
|
-
const readOnlyBuckets = ["knowledge", "schemas", "root"];
|
|
65
|
-
return readOnlyBuckets.some(bucket => {
|
|
66
|
-
const bucketRoot = path.join(workspaceRoot, bucket);
|
|
67
|
-
const bucketRelative = path.relative(bucketRoot, fullPath);
|
|
68
|
-
return !bucketRelative.startsWith("..") && !path.isAbsolute(bucketRelative);
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Executes an atomic git transaction (Add + Commit).
|
|
73
|
-
*/
|
|
74
|
-
export async function gitCommit(filePath, message) {
|
|
75
|
-
return new Promise((resolve, reject) => {
|
|
76
|
-
const add = spawn("git", ["add", filePath], { cwd: workspaceRoot });
|
|
77
|
-
add.on("close", (code) => {
|
|
78
|
-
if (code !== 0 && code !== null) {
|
|
79
|
-
return reject(new Error(`Git add failed with code ${code}`));
|
|
80
|
-
}
|
|
81
|
-
const commit = spawn("git", ["commit", "-m", message], { cwd: workspaceRoot });
|
|
82
|
-
commit.on("close", (code) => {
|
|
83
|
-
// If code is not 0, it might be "nothing to commit" which is fine for our tools
|
|
84
|
-
resolve();
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
import { execFile } from "child_process";
|
|
3
|
-
import { promisify } from "util";
|
|
4
|
-
import { validatePath, handleToolError } from "../utils.js";
|
|
5
|
-
const execFileAsync = promisify(execFile);
|
|
6
|
-
export function registerSearchTool(server) {
|
|
7
|
-
server.tool("workspace_search", {
|
|
8
|
-
query: z.string().describe("Search query string"),
|
|
9
|
-
scope: z.string().optional().describe("Search scope (e.g., projects, knowledge, or specific project name)")
|
|
10
|
-
}, async ({ query, scope }) => {
|
|
11
|
-
try {
|
|
12
|
-
const target = scope === "root" ? "." : scope || "projects";
|
|
13
|
-
const { fullPath: baseDir } = validatePath(target);
|
|
14
|
-
// Use grep -rnI via execFile (no shell interpolation)
|
|
15
|
-
const { stdout } = await execFileAsync("grep", ["-rnIE", query, "."], { cwd: baseDir });
|
|
16
|
-
const results = stdout.split("\n").slice(0, 50).join("\n");
|
|
17
|
-
return {
|
|
18
|
-
content: [{ type: "text", text: results || "No results found." }],
|
|
19
|
-
isError: false
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
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
|
-
return handleToolError(error);
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|