-
Notifications
You must be signed in to change notification settings - Fork 135
Provide INSTRUCTIONS.md as an MCP resource. #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4,8 +4,9 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { mkdir, writeFile } from "fs/promises"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { mkdir, readFile, writeFile } from "fs/promises"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { dirname, resolve } from "path"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { fileURLToPath } from "url"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { z } from "zod"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { startEmbeddingTracker } from "./core/embedding-tracker.js"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { isBrokenPipeError, runCleanup } from "./core/process-lifecycle.js"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -36,6 +37,8 @@ const passthroughArgs = process.argv.slice(2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const ROOT_DIR = passthroughArgs[0] && !SUB_COMMANDS.includes(passthroughArgs[0]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ? resolve(passthroughArgs[0]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| : process.cwd(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const INSTRUCTIONS_PATH = resolve(dirname(fileURLToPath(import.meta.url)), "../INSTRUCTIONS.md"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const INSTRUCTIONS_RESOURCE_URI = "contextplus://instructions"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| function parseAgentTarget(input?: string): AgentTarget { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const normalized = (input ?? "claude").toLowerCase(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -133,6 +136,18 @@ const server = new McpServer({ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| capabilities: { logging: {} }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| server.resource( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "contextplus_instructions", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| INSTRUCTIONS_RESOURCE_URI, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| async (uri) => ({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| contents: [{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| uri: uri.href, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mimeType: "text/markdown", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| text: await readFile(INSTRUCTIONS_PATH, "utf8"), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+142
to
+148
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| async (uri) => ({ | |
| contents: [{ | |
| uri: uri.href, | |
| mimeType: "text/markdown", | |
| text: await readFile(INSTRUCTIONS_PATH, "utf8"), | |
| }], | |
| }), | |
| async (uri) => { | |
| let text: string; | |
| try { | |
| text = await readFile(INSTRUCTIONS_PATH, "utf8"); | |
| } catch (error) { | |
| text = | |
| "# Context+ Instructions\n\n" + | |
| "The instructions file could not be loaded from the expected location.\n\n" + | |
| `Expected path: \`${INSTRUCTIONS_PATH}\`.\n\n` + | |
| "This may indicate a packaging or installation issue. Please ensure that the `INSTRUCTIONS.md` file " + | |
| "is included in the installed package and that the path resolution is correct."; | |
| } | |
| return { | |
| contents: [ | |
| { | |
| uri: uri.href, | |
| mimeType: "text/markdown", | |
| text, | |
| }, | |
| ], | |
| }; | |
| }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This reads INSTRUCTIONS.md from disk on every resource request. Since the content is static, consider reading it once at startup (or memoizing it) to avoid repeated filesystem I/O and simplify failure handling (single place to report missing file).