Provide INSTRUCTIONS.md as an MCP resource.#12
Provide INSTRUCTIONS.md as an MCP resource.#12ForLoopCodes merged 1 commit intoForLoopCodes:mainfrom
Conversation
Pasting INSTRUCTIONS.md into shared projects might be unwelcome clutter. Providing it as an MCP resource that user-configured agent preferences can refer to helps with this.
|
@eamsden is attempting to deploy a commit to the ForLoopCodes' projects Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
Pull request overview
Adds an MCP resource that serves the repository’s INSTRUCTIONS.md, allowing agent preferences to reference the instructions without copying the file into user projects.
Changes:
- Introduces constants for the on-disk
INSTRUCTIONS.mdlocation and a stable resource URI. - Registers a new MCP resource (
contextplus_instructions) that returnsINSTRUCTIONS.mdastext/markdown.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| async (uri) => ({ | ||
| contents: [{ | ||
| uri: uri.href, | ||
| mimeType: "text/markdown", | ||
| text: await readFile(INSTRUCTIONS_PATH, "utf8"), | ||
| }], | ||
| }), |
There was a problem hiding this comment.
The resource handler directly awaits readFile(INSTRUCTIONS_PATH). If INSTRUCTIONS.md is missing from the installed package (or the path resolution changes), this will throw and may fail the resource request (and possibly bubble up as a server error). Consider catching readFile errors here and returning a clear, deterministic message (or fallback content) rather than letting the exception propagate.
| 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, | |
| }, | |
| ], | |
| }; | |
| }, |
| server.resource( | ||
| "contextplus_instructions", | ||
| INSTRUCTIONS_RESOURCE_URI, | ||
| async (uri) => ({ | ||
| contents: [{ | ||
| uri: uri.href, | ||
| mimeType: "text/markdown", | ||
| text: await readFile(INSTRUCTIONS_PATH, "utf8"), | ||
| }], |
There was a problem hiding this comment.
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).
Pasting INSTRUCTIONS.md into shared projects might be unwelcome clutter. Providing it as an MCP resource that user-configured agent preferences can refer to helps with this.