Skip to content

Commit eca1f22

Browse files
committed
feat: enhance MCP server update process and documentation
- Update the `getServerContent` function to display code with line numbers for easier reference. - Revise the update process for existing MCP servers: - Prefer focused changes using `updateServer` with `updateType="section"` or `updateType="add"`. - Provide detailed instructions for using line numbers when making updates. - Clarify the requirements for updating the Claude Desktop config with new environment variables. - Improve error messages and documentation for tools like `updateMcpServer`, including more specific parameters. - Add new resources for handling Jira epics, including creation and retrieval functionalities. - Introduce additional tools for managing issues, such as creating, updating, and adding comments to issues. - Ensure all server interactions are well-documented and user-friendly by providing clear messages on successful operations and error states.
1 parent e2d9083 commit eca1f22

File tree

3 files changed

+1289
-26
lines changed

3 files changed

+1289
-26
lines changed

creator-server.ts

Lines changed: 225 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,20 @@ When a user asks for a new MCP server:
8181
### SCENARIO 2: UPDATING AN EXISTING MCP SERVER
8282
When a user wants to update an existing server or if there is already a server with same functionality:
8383
1. Use listServers to show available servers
84-
2. Retrieve the current code with getServerContent
84+
2. Retrieve the current code with getServerContent, which will display the code with line numbers
8585
3. Analyze the existing structure before making changes
86-
4. Preserve existing functionality while adding new features
87-
5. Follow the same code standards as the original
88-
6. Install any new dependencies needed
89-
7. Update the Claude Desktop config if new environment variables are needed
90-
8. Clearly explain what changes you made
86+
4. For updates, prefer focused, targeted changes over complete rewrites:
87+
- Use updateServer with updateType="section" to modify specific parts
88+
- Use updateServer with updateType="add" to insert new functionality
89+
- Only use updateServer with updateType="full" when extensive changes are needed
90+
5. When using updateServer with "section" or "add" types:
91+
- ALWAYS refer to the exact line numbers shown in getServerContent output
92+
- Double-check that your start/end lines match the correct sections of code
93+
- Validate that insertAfterLine is the exact line where you want to insert code
94+
6. Follow the same code standards as the original
95+
7. Install any new dependencies needed
96+
8. Explain how to update the Claude Desktop config if new environment variables are needed
97+
9. Clearly explain what changes you made
9198
9299
## CODE IMPLEMENTATION REQUIREMENTS
93100
- All servers must use the TypeScript SDK
@@ -101,7 +108,7 @@ When a user wants to update an existing server or if there is already a server w
101108
## HANDLING API KEYS AND AUTHENTICATION
102109
- If an API requires authentication, explain this requirement to the user
103110
- API keys should ALWAYS be handled using environment variables configured in the Claude Desktop config
104-
- When registering a server that requires API keys, update the Claude config to include placeholders for these keys
111+
- When registering a server that requires API keys, clearly explain what environment variables need to be set in the Claude config
105112
- In your code, access API keys using process.env.KEY_NAME
106113
- Add clear validation for environment variables and helpful error messages if they're missing
107114
- Clearly tell users which environment variables they need to set in the Claude Desktop config
@@ -111,17 +118,17 @@ When a user wants to update an existing server or if there is already a server w
111118
112119
## TOOLS TO USE
113120
- listServers: To show available servers
114-
- getServerContent: To retrieve existing server code
121+
- getServerContent: To retrieve existing server code with line numbers
115122
- getTemplate: To see example MCP server structure
116123
- createMcpServer: To save a new server and register with Claude
117-
- updateServer: To modify an existing server
124+
- updateMcpServer: To update an existing server (full rewrite, section update, or add code)
118125
- analyzeServerDependencies: To identify required packages
119126
- installServerDependencies: To install npm packages
120127
- getClaudeConfig: To get the current Claude Desktop configuration
121128
- updateClaudeConfig: To update the Claude Desktop configuration with any environment variables needed
122129
123130
After creating or updating a server, provide a brief summary of what the server does and how to use it. Remind users to:
124-
1. Edit their Claude Desktop config to add actual API keys (replacing any placeholders)
131+
1. Update their Claude Desktop config to add actual API keys if needed
125132
2. Install any required npm dependencies
126133
3. Restart Claude Desktop after updating the server and config to apply changes
127134
@@ -242,7 +249,7 @@ server.tool(
242249
content: [
243250
{
244251
type: "text",
245-
text: `Error: Server "${serverName}" already exists at ${filePath}. Use 'updateServer' to update it, or set 'overwriteExisting' to true to replace it.`,
252+
text: `Error: Server "${serverName}" already exists at ${filePath}. Use 'updateMcpServer' to update it, or set 'overwriteExisting' to true to replace it.`,
246253
},
247254
],
248255
isError: true,
@@ -381,33 +388,41 @@ Available tools:
381388
- Returns an example MCP server template to help guide development
382389
383390
3. createMcpServer
384-
- Creates a new JavaScript MCP server or updates an existing one
391+
- Creates a new JavaScript MCP server and registers it with Claude Desktop
385392
- Parameters:
386393
- serverName: Name of your server (used for the filename)
387394
- serverCode: The complete JavaScript code for your server
388395
- registerWithClaude: Whether to register with Claude Desktop (default: true)
389396
390397
4. updateMcpServer
391-
- Updates an existing JavaScript MCP server directly
398+
- Updates an existing MCP server with flexible options
392399
- Parameters:
393400
- serverName: Name of the server to update
394-
- serverCode: The updated JavaScript code for your server
401+
- updateType: "full" (replace entire file), "section" (replace specific lines), or "add" (add new code)
402+
- startLine: First line to replace (required for "section" updates)
403+
- endLine: Last line to replace (required for "section" updates)
404+
- insertAfterLine: Line after which to insert code (required for "add" updates)
405+
- code: The new code to add or replace
406+
- description: Optional description of the changes
395407
396408
5. listServers
397409
- Lists all servers created with this tool
398410
399411
6. getClaudeConfig
400412
- Retrieves the current Claude Desktop configuration
413+
- Use this to check the current config before making changes
401414
402415
7. updateClaudeConfig
403-
- Updates the Claude Desktop configuration file
416+
- Updates the Claude Desktop configuration file, including environment variables
404417
- Parameters:
405418
- configData: Complete JSON configuration
419+
- Use this to add API keys and other environment variables your server needs
406420
407421
8. getServerContent
408-
- Retrieves the current content of a server file
422+
- Retrieves the current content of a server file with line numbers
409423
- Parameters:
410424
- serverName: Name of the server to get content for
425+
- Output includes line numbers for precise reference when updating
411426
412427
9. analyzeServerDependencies
413428
- Analyzes a server file to detect npm dependencies
@@ -420,20 +435,36 @@ Available tools:
420435
- dependencies: Array of package names to install
421436
422437
11. getHelp
423-
- Shows this help message
438+
- Shows this help message
424439
425440
Workflow for creating a new server:
426441
1. Ask to create a custom server for your needs
427442
2. Use createMcpServer to save the server and register it with Claude Desktop
428443
3. Use analyzeServerDependencies to detect required packages
429444
4. Use installServerDependencies to install the required packages
445+
5. If needed, update the Claude Desktop config to add any required API keys
430446
431447
Workflow for updating servers:
432448
1. Use listServers to find the exact name of the server you want to update
433-
2. Use getServerContent with the exact server name to retrieve its current code
434-
3. Make your modifications to the code
435-
4. Use updateMcpServer with the server name and modified code to save changes
449+
2. Use getServerContent with the exact server name to retrieve its current code with line numbers
450+
3. Review the code and note the EXACT line numbers from the output for the section you want to modify
451+
4. Choose the right update approach:
452+
- For targeted changes: Use updateServer with updateType="section", providing the exact start and end lines
453+
- For adding new functionality: Use updateServer with updateType="add", specifying the exact line after which to insert
454+
- For complete rewrites: Use updateServer with updateType="full" (line numbers not needed)
436455
5. If you added new dependencies, use analyzeServerDependencies and installServerDependencies
456+
6. If you added new environment variables, update the Claude Desktop config
457+
458+
IMPORTANT: When using "section" or "add" update types, always use the exact line numbers from the getServerContent output to ensure precise updates.
459+
460+
Environment Variables in the Claude Desktop Config:
461+
- Environment variables are stored in the "env" object for each server
462+
- They're accessible in your server code via process.env.KEY
463+
- Example:
464+
"env": {
465+
"OPENAI_API_KEY": "sk-abcdef123456",
466+
"WEATHER_API_KEY": "98765abcdef"
467+
}
437468
`,
438469
},
439470
],
@@ -444,9 +475,22 @@ server.tool(
444475
"updateMcpServer",
445476
{
446477
serverName: z.string().min(1),
447-
serverCode: z.string().min(1),
478+
updateType: z.enum(["full", "section", "add"]),
479+
startLine: z.number().int().positive().optional(),
480+
endLine: z.number().int().positive().optional(),
481+
insertAfterLine: z.number().int().positive().optional(),
482+
code: z.string().min(1),
483+
description: z.string().optional(),
448484
},
449-
async ({ serverName, serverCode }) => {
485+
async ({
486+
serverName,
487+
updateType,
488+
startLine,
489+
endLine,
490+
insertAfterLine,
491+
code,
492+
description,
493+
}) => {
450494
try {
451495
const nameWithoutExtension = serverName.endsWith(".js")
452496
? serverName.slice(0, -3)
@@ -465,22 +509,170 @@ server.tool(
465509
content: [
466510
{
467511
type: "text",
468-
text: `Error: Server "${nameWithoutExtension}" does not exist. Please use 'listServers' first to see available servers, then use 'createServer' to create a new server if needed.`,
512+
text: `Error: Server "${nameWithoutExtension}" does not exist. Please use 'listServers' first to see available servers.`,
469513
},
470514
],
471515
isError: true,
472516
};
473517
}
474518

475-
await fs.writeFile(filePath, serverCode);
519+
// For full update, just replace the entire file
520+
if (updateType === "full") {
521+
await fs.writeFile(filePath, code);
522+
523+
const updateDetails = description
524+
? `\nUpdate details: ${description}`
525+
: "";
526+
527+
return {
528+
content: [
529+
{
530+
type: "text",
531+
text: `Successfully updated entire MCP server "${nameWithoutExtension}".${updateDetails}`,
532+
},
533+
],
534+
};
535+
}
536+
537+
// For section or add updates, read the current file
538+
const serverCode = await fs.readFile(filePath, "utf-8");
539+
const lines = serverCode.split("\n");
540+
541+
// Handle section update
542+
if (updateType === "section") {
543+
if (!startLine || !endLine) {
544+
return {
545+
content: [
546+
{
547+
type: "text",
548+
text: `Error: When using updateType "section", both startLine and endLine must be provided.`,
549+
},
550+
],
551+
isError: true,
552+
};
553+
}
554+
555+
// Validate line numbers
556+
if (startLine > lines.length || endLine > lines.length) {
557+
return {
558+
content: [
559+
{
560+
type: "text",
561+
text: `Error: Line numbers out of range. The file has ${lines.length} lines, but you specified lines ${startLine}-${endLine}.`,
562+
},
563+
],
564+
isError: true,
565+
};
566+
}
567+
568+
if (startLine > endLine) {
569+
return {
570+
content: [
571+
{
572+
type: "text",
573+
text: `Error: Start line (${startLine}) cannot be greater than end line (${endLine}).`,
574+
},
575+
],
576+
isError: true,
577+
};
578+
}
579+
580+
// Split the new code into lines
581+
const newLines = code.split("\n");
582+
583+
// Replace the specified section with the new code
584+
const updatedLines = [
585+
...lines.slice(0, startLine - 1),
586+
...newLines,
587+
...lines.slice(endLine),
588+
];
589+
590+
// Join the lines back together
591+
const updatedCode = updatedLines.join("\n");
592+
593+
// Write the updated code back to the file
594+
await fs.writeFile(filePath, updatedCode);
595+
596+
const updateDetails = description
597+
? `\nUpdate details: ${description}`
598+
: "";
599+
600+
return {
601+
content: [
602+
{
603+
type: "text",
604+
text: `Successfully updated lines ${startLine}-${endLine} of MCP server "${nameWithoutExtension}".${updateDetails}`,
605+
},
606+
],
607+
};
608+
}
609+
610+
// Handle add update
611+
if (updateType === "add") {
612+
if (!insertAfterLine) {
613+
return {
614+
content: [
615+
{
616+
type: "text",
617+
text: `Error: When using updateType "add", insertAfterLine must be provided.`,
618+
},
619+
],
620+
isError: true,
621+
};
622+
}
623+
624+
// Validate line number
625+
if (insertAfterLine > lines.length) {
626+
return {
627+
content: [
628+
{
629+
type: "text",
630+
text: `Error: Line number out of range. The file has ${lines.length} lines, but you specified to insert after line ${insertAfterLine}.`,
631+
},
632+
],
633+
isError: true,
634+
};
635+
}
636+
637+
// Split the new code into lines
638+
const newLines = code.split("\n");
639+
640+
// Insert the new code after the specified line
641+
const updatedLines = [
642+
...lines.slice(0, insertAfterLine),
643+
...newLines,
644+
...lines.slice(insertAfterLine),
645+
];
646+
647+
// Join the lines back together
648+
const updatedCode = updatedLines.join("\n");
476649

650+
// Write the updated code back to the file
651+
await fs.writeFile(filePath, updatedCode);
652+
653+
const updateDetails = description
654+
? `\nAddition details: ${description}`
655+
: "";
656+
657+
return {
658+
content: [
659+
{
660+
type: "text",
661+
text: `Successfully added new code after line ${insertAfterLine} of MCP server "${nameWithoutExtension}".${updateDetails}`,
662+
},
663+
],
664+
};
665+
}
666+
667+
// This should never happen due to zod validation, but just in case
477668
return {
478669
content: [
479670
{
480671
type: "text",
481-
text: `Successfully updated MCP server "${nameWithoutExtension}" at ${filePath}.`,
672+
text: `Error: Invalid updateType "${updateType}". Must be one of: "full", "section", or "add".`,
482673
},
483674
],
675+
isError: true,
484676
};
485677
} catch (error) {
486678
return {
@@ -531,11 +723,18 @@ server.tool(
531723

532724
const serverCode = await fs.readFile(filePath, "utf-8");
533725

726+
// Add line numbers to the code for better reference
727+
const lines = serverCode.split("\n");
728+
const numberedLines = lines.map(
729+
(line, index) => `${(index + 1).toString().padStart(4, " ")}| ${line}`
730+
);
731+
const numberedCode = numberedLines.join("\n");
732+
534733
return {
535734
content: [
536735
{
537736
type: "text",
538-
text: `Server "${nameWithoutExtension}" content:\n\n${serverCode}`,
737+
text: `Server "${nameWithoutExtension}" content with line numbers:\n\n${numberedCode}\n\nTotal lines: ${lines.length}`,
539738
},
540739
],
541740
};

0 commit comments

Comments
 (0)