-
Notifications
You must be signed in to change notification settings - Fork 2
⚙️ FEATURE-#36: Share MCP servers with pycodeloop's native saved: registry #37
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
db3090f
⚙️ FEATURE-#36: Add reader/writer for pycodeloop's saved MCP server r…
FernandoCelmer c86f3d5
❤️ TEST-#36: Cover splitCommand tokenizing
FernandoCelmer 26fe7c2
⚙️ FEATURE-#36: Offer to save new MCP servers into the shared pycodel…
FernandoCelmer c2faa20
📝 LINT-#36: Drop JSDoc-style comment blocks
FernandoCelmer 83a608f
🪲 BUG-#36: Make registry I/O async, guard write errors, and confirm n…
FernandoCelmer 7ea80db
🪲 BUG-#36: Handle registry save failures and name conflicts in maybeS…
FernandoCelmer 89b7e00
🔀 MERGE: Resolve conflict between feature/36 and master
FernandoCelmer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| import * as fs from "fs"; | ||
| import * as os from "os"; | ||
| import * as path from "path"; | ||
|
|
||
| const CONFIG_PATH = path.join(os.homedir(), ".pycodeloop", "config.json"); | ||
| const SECTION = "mcp_servers"; | ||
|
|
||
| export interface SavedMcpServer { | ||
| command: string; | ||
| args: string[]; | ||
| env?: Record<string, string>; | ||
| } | ||
|
|
||
| export class McpServerNameTakenError extends Error { | ||
| constructor(readonly name: string) { | ||
| super(`A server named "${name}" already exists in the registry.`); | ||
| } | ||
| } | ||
|
|
||
| async function readConfig(): Promise<Record<string, unknown>> { | ||
| try { | ||
| return JSON.parse(await fs.promises.readFile(CONFIG_PATH, "utf8")); | ||
| } catch { | ||
|
FernandoCelmer marked this conversation as resolved.
FernandoCelmer marked this conversation as resolved.
|
||
| return {}; | ||
| } | ||
| } | ||
|
|
||
| async function writeConfig(data: Record<string, unknown>): Promise<void> { | ||
| await fs.promises.mkdir(path.dirname(CONFIG_PATH), { recursive: true }); | ||
| await fs.promises.writeFile(CONFIG_PATH, JSON.stringify(data, null, 2)); | ||
| } | ||
|
FernandoCelmer marked this conversation as resolved.
|
||
|
|
||
| // Mirrors shlex.split() on the pycodeloop side (cli/flow.py's _load_mcp_tools). | ||
| export function splitCommand(command: string): { command: string; args: string[] } { | ||
| const tokens = command.match(/"[^"]*"|'[^']*'|\S+/g) ?? []; | ||
| const unquoted = tokens.map((t) => | ||
| (t.startsWith('"') && t.endsWith('"')) || (t.startsWith("'") && t.endsWith("'")) | ||
| ? t.slice(1, -1) | ||
| : t | ||
| ); | ||
| const [head, ...rest] = unquoted; | ||
| return { command: head ?? "", args: rest }; | ||
| } | ||
|
|
||
| export async function listSavedMcpServers(): Promise<Record<string, SavedMcpServer>> { | ||
| const data = await readConfig(); | ||
| return (data[SECTION] as Record<string, SavedMcpServer>) ?? {}; | ||
| } | ||
|
|
||
| export async function saveMcpServer( | ||
| name: string, | ||
| server: SavedMcpServer, | ||
| { overwrite = false }: { overwrite?: boolean } = {} | ||
| ): Promise<void> { | ||
| const data = await readConfig(); | ||
| const servers = (data[SECTION] as Record<string, SavedMcpServer>) ?? {}; | ||
| if (servers[name] && !overwrite) { | ||
| throw new McpServerNameTakenError(name); | ||
| } | ||
| servers[name] = server; | ||
| data[SECTION] = servers; | ||
|
FernandoCelmer marked this conversation as resolved.
|
||
| await writeConfig(data); | ||
| } | ||
|
|
||
| export async function deleteSavedMcpServer(name: string): Promise<void> { | ||
| const data = await readConfig(); | ||
| const servers = (data[SECTION] as Record<string, SavedMcpServer>) ?? {}; | ||
| delete servers[name]; | ||
| data[SECTION] = servers; | ||
| await writeConfig(data); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import assert from "node:assert/strict"; | ||
| import { test } from "node:test"; | ||
| import { splitCommand } from "../src/services/mcpRegistry.service"; | ||
|
|
||
| test("splitCommand splits a bare command with no args", () => { | ||
| assert.deepEqual(splitCommand("npx"), { command: "npx", args: [] }); | ||
| }); | ||
|
|
||
| test("splitCommand splits command and positional args", () => { | ||
| assert.deepEqual(splitCommand("npx -y @modelcontextprotocol/server-filesystem ."), { | ||
| command: "npx", | ||
| args: ["-y", "@modelcontextprotocol/server-filesystem", "."], | ||
| }); | ||
| }); | ||
|
|
||
| test("splitCommand keeps a double-quoted argument as one token", () => { | ||
| assert.deepEqual(splitCommand('node server.js "a path/with spaces"'), { | ||
| command: "node", | ||
| args: ["server.js", "a path/with spaces"], | ||
| }); | ||
| }); | ||
|
|
||
| test("splitCommand keeps a single-quoted argument as one token", () => { | ||
| assert.deepEqual(splitCommand("node server.js 'a path/with spaces'"), { | ||
| command: "node", | ||
| args: ["server.js", "a path/with spaces"], | ||
| }); | ||
| }); | ||
|
|
||
| test("splitCommand collapses extra whitespace between tokens", () => { | ||
| assert.deepEqual(splitCommand("npx -y server"), { | ||
| command: "npx", | ||
| args: ["-y", "server"], | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.