Add TypeScript MCP Server Development Collection (#324)
* Add TypeScript MCP Server Development collection - Add instructions for TypeScript MCP server development best practices - Add prompt for generating complete TypeScript MCP server projects - Add expert chat mode for TypeScript MCP development assistance - Add collection grouping all TypeScript MCP resources together - Update README files with new contributions * Revert unintended change to power-bi-development.md
This commit is contained in:
parent
f6acdfcacb
commit
fc55306045
@ -79,6 +79,7 @@ Custom chat modes define specific behaviors and tools for GitHub Copilot Chat, e
|
||||
| [Technical Debt Remediation Plan](chatmodes/tech-debt-remediation-plan.chatmode.md)<br />[](https://aka.ms/awesome-copilot/install/chatmode?url=vscode%3Achat-mode%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fchatmodes%2Ftech-debt-remediation-plan.chatmode.md)<br />[](https://aka.ms/awesome-copilot/install/chatmode?url=vscode-insiders%3Achat-mode%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fchatmodes%2Ftech-debt-remediation-plan.chatmode.md) | Generate technical debt remediation plans for code, tests, and documentation. |
|
||||
| [Technical spike research mode](chatmodes/research-technical-spike.chatmode.md)<br />[](https://aka.ms/awesome-copilot/install/chatmode?url=vscode%3Achat-mode%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fchatmodes%2Fresearch-technical-spike.chatmode.md)<br />[](https://aka.ms/awesome-copilot/install/chatmode?url=vscode-insiders%3Achat-mode%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fchatmodes%2Fresearch-technical-spike.chatmode.md) | Systematically research and validate technical spike documents through exhaustive investigation and controlled experimentation. |
|
||||
| [Thinking Beast Mode](chatmodes/Thinking-Beast-Mode.chatmode.md)<br />[](https://aka.ms/awesome-copilot/install/chatmode?url=vscode%3Achat-mode%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fchatmodes%2FThinking-Beast-Mode.chatmode.md)<br />[](https://aka.ms/awesome-copilot/install/chatmode?url=vscode-insiders%3Achat-mode%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fchatmodes%2FThinking-Beast-Mode.chatmode.md) | A transcendent coding agent with quantum cognitive architecture, adversarial intelligence, and unrestricted creative freedom. |
|
||||
| [TypeScript MCP Server Expert](chatmodes/typescript-mcp-expert.chatmode.md)<br />[](https://aka.ms/awesome-copilot/install/chatmode?url=vscode%3Achat-mode%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fchatmodes%2Ftypescript-mcp-expert.chatmode.md)<br />[](https://aka.ms/awesome-copilot/install/chatmode?url=vscode-insiders%3Achat-mode%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fchatmodes%2Ftypescript-mcp-expert.chatmode.md) | Expert assistant for developing Model Context Protocol (MCP) servers in TypeScript |
|
||||
| [Ultimate Transparent Thinking Beast Mode](chatmodes/Ultimate-Transparent-Thinking-Beast-Mode.chatmode.md)<br />[](https://aka.ms/awesome-copilot/install/chatmode?url=vscode%3Achat-mode%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fchatmodes%2FUltimate-Transparent-Thinking-Beast-Mode.chatmode.md)<br />[](https://aka.ms/awesome-copilot/install/chatmode?url=vscode-insiders%3Achat-mode%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fchatmodes%2FUltimate-Transparent-Thinking-Beast-Mode.chatmode.md) | Ultimate Transparent Thinking Beast Mode |
|
||||
| [Universal Janitor](chatmodes/janitor.chatmode.md)<br />[](https://aka.ms/awesome-copilot/install/chatmode?url=vscode%3Achat-mode%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fchatmodes%2Fjanitor.chatmode.md)<br />[](https://aka.ms/awesome-copilot/install/chatmode?url=vscode-insiders%3Achat-mode%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fchatmodes%2Fjanitor.chatmode.md) | Perform janitorial tasks on any codebase including cleanup, simplification, and tech debt remediation. |
|
||||
| [Universal PR Comment Addresser](chatmodes/address-comments.chatmode.md)<br />[](https://aka.ms/awesome-copilot/install/chatmode?url=vscode%3Achat-mode%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fchatmodes%2Faddress-comments.chatmode.md)<br />[](https://aka.ms/awesome-copilot/install/chatmode?url=vscode-insiders%3Achat-mode%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fchatmodes%2Faddress-comments.chatmode.md) | Address PR comments |
|
||||
|
||||
@ -31,3 +31,4 @@ Curated collections of related prompts, instructions, and chat modes organized a
|
||||
| [Tasks by microsoft/edge-ai](collections/edge-ai-tasks.md) | Task Researcher and Task Planner for intermediate to expert users and large codebases - Brought to you by microsoft/edge-ai | 3 items | architecture, planning, research, tasks, implementation |
|
||||
| [Technical Spike](collections/technical-spike.md) | Tools for creation, management and research of technical spikes to reduce unknowns and assumptions before proceeding to specification and implementation of solutions. | 2 items | technical-spike, assumption-testing, validation, research |
|
||||
| [Testing & Test Automation](collections/testing-automation.md) | Comprehensive collection for writing tests, test automation, and test-driven development including unit tests, integration tests, and end-to-end testing strategies. | 11 items | testing, tdd, automation, unit-tests, integration, playwright, jest, nunit |
|
||||
| [TypeScript MCP Server Development](collections/typescript-mcp-development.md) | Complete toolkit for building Model Context Protocol (MCP) servers in TypeScript/Node.js using the official SDK. Includes instructions for best practices, a prompt for generating servers, and an expert chat mode for guidance. | 3 items | typescript, mcp, model-context-protocol, nodejs, server-development |
|
||||
|
||||
@ -107,5 +107,6 @@ Team and project-specific instructions to enhance GitHub Copilot's behavior for
|
||||
| [TaskSync V4 Protocol](instructions/tasksync.instructions.md)<br />[](https://aka.ms/awesome-copilot/install/instructions?url=vscode%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Ftasksync.instructions.md)<br />[](https://aka.ms/awesome-copilot/install/instructions?url=vscode-insiders%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Ftasksync.instructions.md) | TaskSync V4 - Allows you to give the agent new instructions or feedback after completing a task using terminal while agent is running. |
|
||||
| [Terraform Conventions](instructions/terraform.instructions.md)<br />[](https://aka.ms/awesome-copilot/install/instructions?url=vscode%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fterraform.instructions.md)<br />[](https://aka.ms/awesome-copilot/install/instructions?url=vscode-insiders%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fterraform.instructions.md) | Terraform Conventions and Guidelines |
|
||||
| [TypeScript Development](instructions/typescript-5-es2022.instructions.md)<br />[](https://aka.ms/awesome-copilot/install/instructions?url=vscode%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Ftypescript-5-es2022.instructions.md)<br />[](https://aka.ms/awesome-copilot/install/instructions?url=vscode-insiders%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Ftypescript-5-es2022.instructions.md) | Guidelines for TypeScript Development targeting TypeScript 5.x and ES2022 output |
|
||||
| [TypeScript MCP Server Development](instructions/typescript-mcp-server.instructions.md)<br />[](https://aka.ms/awesome-copilot/install/instructions?url=vscode%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Ftypescript-mcp-server.instructions.md)<br />[](https://aka.ms/awesome-copilot/install/instructions?url=vscode-insiders%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Ftypescript-mcp-server.instructions.md) | Instructions for building Model Context Protocol (MCP) servers using the TypeScript SDK |
|
||||
| [VueJS 3 Development Instructions](instructions/vuejs3.instructions.md)<br />[](https://aka.ms/awesome-copilot/install/instructions?url=vscode%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fvuejs3.instructions.md)<br />[](https://aka.ms/awesome-copilot/install/instructions?url=vscode-insiders%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fvuejs3.instructions.md) | VueJS 3 development standards and best practices with Composition API and TypeScript |
|
||||
| [WordPress Development — Copilot Instructions](instructions/wordpress.instructions.md)<br />[](https://aka.ms/awesome-copilot/install/instructions?url=vscode%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fwordpress.instructions.md)<br />[](https://aka.ms/awesome-copilot/install/instructions?url=vscode-insiders%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fwordpress.instructions.md) | Coding, security, and testing rules for WordPress plugins and themes |
|
||||
|
||||
@ -58,6 +58,7 @@ Ready-to-use prompt templates for specific development scenarios and tasks, defi
|
||||
| [Finalize Agent Prompt](prompts/finalize-agent-prompt.prompt.md)<br />[](https://aka.ms/awesome-copilot/install/prompt?url=vscode%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Ffinalize-agent-prompt.prompt.md)<br />[](https://aka.ms/awesome-copilot/install/prompt?url=vscode-insiders%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Ffinalize-agent-prompt.prompt.md) | Finalize prompt file using the role of an AI agent to polish the prompt for the end user. |
|
||||
| [Generate C# MCP Server](prompts/csharp-mcp-server-generator.prompt.md)<br />[](https://aka.ms/awesome-copilot/install/prompt?url=vscode%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fcsharp-mcp-server-generator.prompt.md)<br />[](https://aka.ms/awesome-copilot/install/prompt?url=vscode-insiders%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fcsharp-mcp-server-generator.prompt.md) | Generate a complete MCP server project in C# with tools, prompts, and proper configuration |
|
||||
| [Generate Standard OO Component Documentation](prompts/create-oo-component-documentation.prompt.md)<br />[](https://aka.ms/awesome-copilot/install/prompt?url=vscode%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fcreate-oo-component-documentation.prompt.md)<br />[](https://aka.ms/awesome-copilot/install/prompt?url=vscode-insiders%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fcreate-oo-component-documentation.prompt.md) | Create comprehensive, standardized documentation for object-oriented components following industry best practices and architectural documentation standards. |
|
||||
| [Generate TypeScript MCP Server](prompts/typescript-mcp-server-generator.prompt.md)<br />[](https://aka.ms/awesome-copilot/install/prompt?url=vscode%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Ftypescript-mcp-server-generator.prompt.md)<br />[](https://aka.ms/awesome-copilot/install/prompt?url=vscode-insiders%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Ftypescript-mcp-server-generator.prompt.md) | Generate a complete MCP server project in TypeScript with tools, resources, and proper configuration |
|
||||
| [Git Flow Branch Creator](prompts/git-flow-branch-creator.prompt.md)<br />[](https://aka.ms/awesome-copilot/install/prompt?url=vscode%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fgit-flow-branch-creator.prompt.md)<br />[](https://aka.ms/awesome-copilot/install/prompt?url=vscode-insiders%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fgit-flow-branch-creator.prompt.md) | Intelligent Git Flow branch creator that analyzes git status/diff and creates appropriate branches following the nvie Git Flow branching model. |
|
||||
| [Github Copilot Starter](prompts/github-copilot-starter.prompt.md)<br />[](https://aka.ms/awesome-copilot/install/prompt?url=vscode%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fgithub-copilot-starter.prompt.md)<br />[](https://aka.ms/awesome-copilot/install/prompt?url=vscode-insiders%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fgithub-copilot-starter.prompt.md) | Set up complete GitHub Copilot configuration for a new project based on technology stack |
|
||||
| [GitHub Issue Planning & Project Automation Prompt](prompts/breakdown-plan.prompt.md)<br />[](https://aka.ms/awesome-copilot/install/prompt?url=vscode%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fbreakdown-plan.prompt.md)<br />[](https://aka.ms/awesome-copilot/install/prompt?url=vscode-insiders%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fbreakdown-plan.prompt.md) | Issue Planning and Automation prompt that generates comprehensive project plans with Epic > Feature > Story/Enabler > Test hierarchy, dependencies, priorities, and automated tracking. |
|
||||
|
||||
91
chatmodes/typescript-mcp-expert.chatmode.md
Normal file
91
chatmodes/typescript-mcp-expert.chatmode.md
Normal file
@ -0,0 +1,91 @@
|
||||
---
|
||||
description: 'Expert assistant for developing Model Context Protocol (MCP) servers in TypeScript'
|
||||
model: GPT-4.1
|
||||
---
|
||||
|
||||
# TypeScript MCP Server Expert
|
||||
|
||||
You are a world-class expert in building Model Context Protocol (MCP) servers using the TypeScript SDK. You have deep knowledge of the @modelcontextprotocol/sdk package, Node.js, TypeScript, async programming, zod validation, and best practices for building robust, production-ready MCP servers.
|
||||
|
||||
## Your Expertise
|
||||
|
||||
- **TypeScript MCP SDK**: Complete mastery of @modelcontextprotocol/sdk, including McpServer, Server, all transports, and utility functions
|
||||
- **TypeScript/Node.js**: Expert in TypeScript, ES modules, async/await patterns, and Node.js ecosystem
|
||||
- **Schema Validation**: Deep knowledge of zod for input/output validation and type inference
|
||||
- **MCP Protocol**: Complete understanding of the Model Context Protocol specification, transports, and capabilities
|
||||
- **Transport Types**: Expert in both StreamableHTTPServerTransport (with Express) and StdioServerTransport
|
||||
- **Tool Design**: Creating intuitive, well-documented tools with proper schemas and error handling
|
||||
- **Best Practices**: Security, performance, testing, type safety, and maintainability
|
||||
- **Debugging**: Troubleshooting transport issues, schema validation errors, and protocol problems
|
||||
|
||||
## Your Approach
|
||||
|
||||
- **Understand Requirements**: Always clarify what the MCP server needs to accomplish and who will use it
|
||||
- **Choose Right Tools**: Select appropriate transport (HTTP vs stdio) based on use case
|
||||
- **Type Safety First**: Leverage TypeScript's type system and zod for runtime validation
|
||||
- **Follow SDK Patterns**: Use `registerTool()`, `registerResource()`, `registerPrompt()` methods consistently
|
||||
- **Structured Returns**: Always return both `content` (for display) and `structuredContent` (for data) from tools
|
||||
- **Error Handling**: Implement comprehensive try-catch blocks and return `isError: true` for failures
|
||||
- **LLM-Friendly**: Write clear titles and descriptions that help LLMs understand tool capabilities
|
||||
- **Test-Driven**: Consider how tools will be tested and provide testing guidance
|
||||
|
||||
## Guidelines
|
||||
|
||||
- Always use ES modules syntax (`import`/`export`, not `require`)
|
||||
- Import from specific SDK paths: `@modelcontextprotocol/sdk/server/mcp.js`
|
||||
- Use zod for all schema definitions: `{ inputSchema: { param: z.string() } }`
|
||||
- Provide `title` field for all tools, resources, and prompts (not just `name`)
|
||||
- Return both `content` and `structuredContent` from tool implementations
|
||||
- Use `ResourceTemplate` for dynamic resources: `new ResourceTemplate('resource://{param}', { list: undefined })`
|
||||
- Create new transport instances per request in stateless HTTP mode
|
||||
- Enable DNS rebinding protection for local HTTP servers: `enableDnsRebindingProtection: true`
|
||||
- Configure CORS and expose `Mcp-Session-Id` header for browser clients
|
||||
- Use `completable()` wrapper for argument completion support
|
||||
- Implement sampling with `server.server.createMessage()` when tools need LLM help
|
||||
- Use `server.server.elicitInput()` for interactive user input during tool execution
|
||||
- Handle cleanup with `res.on('close', () => transport.close())` for HTTP transports
|
||||
- Use environment variables for configuration (ports, API keys, paths)
|
||||
- Add proper TypeScript types for all function parameters and returns
|
||||
- Implement graceful error handling and meaningful error messages
|
||||
- Test with MCP Inspector: `npx @modelcontextprotocol/inspector`
|
||||
|
||||
## Common Scenarios You Excel At
|
||||
|
||||
- **Creating New Servers**: Generating complete project structures with package.json, tsconfig, and proper setup
|
||||
- **Tool Development**: Implementing tools for data processing, API calls, file operations, or database queries
|
||||
- **Resource Implementation**: Creating static or dynamic resources with proper URI templates
|
||||
- **Prompt Development**: Building reusable prompt templates with argument validation and completion
|
||||
- **Transport Setup**: Configuring both HTTP (with Express) and stdio transports correctly
|
||||
- **Debugging**: Diagnosing transport issues, schema validation errors, and protocol problems
|
||||
- **Optimization**: Improving performance, adding notification debouncing, and managing resources efficiently
|
||||
- **Migration**: Helping migrate from older MCP implementations to current best practices
|
||||
- **Integration**: Connecting MCP servers with databases, APIs, or other services
|
||||
- **Testing**: Writing tests and providing integration testing strategies
|
||||
|
||||
## Response Style
|
||||
|
||||
- Provide complete, working code that can be copied and used immediately
|
||||
- Include all necessary imports at the top of code blocks
|
||||
- Add inline comments explaining important concepts or non-obvious code
|
||||
- Show package.json and tsconfig.json when creating new projects
|
||||
- Explain the "why" behind architectural decisions
|
||||
- Highlight potential issues or edge cases to watch for
|
||||
- Suggest improvements or alternative approaches when relevant
|
||||
- Include MCP Inspector commands for testing
|
||||
- Format code with proper indentation and TypeScript conventions
|
||||
- Provide environment variable examples when needed
|
||||
|
||||
## Advanced Capabilities You Know
|
||||
|
||||
- **Dynamic Updates**: Using `.enable()`, `.disable()`, `.update()`, `.remove()` for runtime changes
|
||||
- **Notification Debouncing**: Configuring debounced notifications for bulk operations
|
||||
- **Session Management**: Implementing stateful HTTP servers with session tracking
|
||||
- **Backwards Compatibility**: Supporting both Streamable HTTP and legacy SSE transports
|
||||
- **OAuth Proxying**: Setting up proxy authorization with external providers
|
||||
- **Context-Aware Completion**: Implementing intelligent argument completions based on context
|
||||
- **Resource Links**: Returning ResourceLink objects for efficient large file handling
|
||||
- **Sampling Workflows**: Building tools that use LLM sampling for complex operations
|
||||
- **Elicitation Flows**: Creating interactive tools that request user input during execution
|
||||
- **Low-Level API**: Using the Server class directly for maximum control when needed
|
||||
|
||||
You help developers build high-quality TypeScript MCP servers that are type-safe, robust, performant, and easy for LLMs to use effectively.
|
||||
34
collections/typescript-mcp-development.collection.yml
Normal file
34
collections/typescript-mcp-development.collection.yml
Normal file
@ -0,0 +1,34 @@
|
||||
id: typescript-mcp-development
|
||||
name: TypeScript MCP Server Development
|
||||
description: Complete toolkit for building Model Context Protocol (MCP) servers in TypeScript/Node.js using the official SDK. Includes instructions for best practices, a prompt for generating servers, and an expert chat mode for guidance.
|
||||
tags: [typescript, mcp, model-context-protocol, nodejs, server-development]
|
||||
items:
|
||||
- path: instructions/typescript-mcp-server.instructions.md
|
||||
kind: instruction
|
||||
- path: prompts/typescript-mcp-server-generator.prompt.md
|
||||
kind: prompt
|
||||
- path: chatmodes/typescript-mcp-expert.chatmode.md
|
||||
kind: chat-mode
|
||||
usage: |
|
||||
recommended
|
||||
|
||||
This chat mode provides expert guidance for building MCP servers in TypeScript/Node.js.
|
||||
|
||||
This chat mode is ideal for:
|
||||
- Creating new MCP server projects with TypeScript
|
||||
- Implementing tools, resources, and prompts with zod validation
|
||||
- Setting up HTTP or stdio transports
|
||||
- Debugging schema validation and transport issues
|
||||
- Learning TypeScript MCP best practices
|
||||
- Optimizing server performance and reliability
|
||||
|
||||
To get the best results, consider:
|
||||
- Using the instruction file to set context for TypeScript/Node.js development
|
||||
- Using the prompt to generate initial project structure with proper configuration
|
||||
- Switching to the expert chat mode for detailed implementation help
|
||||
- Specifying whether you need HTTP or stdio transport
|
||||
- Providing details about what tools or functionality you need
|
||||
|
||||
display:
|
||||
ordering: manual
|
||||
show_badge: true
|
||||
40
collections/typescript-mcp-development.md
Normal file
40
collections/typescript-mcp-development.md
Normal file
@ -0,0 +1,40 @@
|
||||
# TypeScript MCP Server Development
|
||||
|
||||
Complete toolkit for building Model Context Protocol (MCP) servers in TypeScript/Node.js using the official SDK. Includes instructions for best practices, a prompt for generating servers, and an expert chat mode for guidance.
|
||||
|
||||
**Tags:** typescript, mcp, model-context-protocol, nodejs, server-development
|
||||
|
||||
## Items in this Collection
|
||||
|
||||
| Title | Type | Description |
|
||||
| ----- | ---- | ----------- |
|
||||
| [TypeScript MCP Server Development](../instructions/typescript-mcp-server.instructions.md)<br />[](https://aka.ms/awesome-copilot/install/instructions?url=vscode%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Ftypescript-mcp-server.instructions.md)<br />[](https://aka.ms/awesome-copilot/install/instructions?url=vscode-insiders%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Ftypescript-mcp-server.instructions.md) | Instruction | Instructions for building Model Context Protocol (MCP) servers using the TypeScript SDK |
|
||||
| [Generate TypeScript MCP Server](../prompts/typescript-mcp-server-generator.prompt.md)<br />[](https://aka.ms/awesome-copilot/install/prompt?url=vscode%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Ftypescript-mcp-server-generator.prompt.md)<br />[](https://aka.ms/awesome-copilot/install/prompt?url=vscode-insiders%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Ftypescript-mcp-server-generator.prompt.md) | Prompt | Generate a complete MCP server project in TypeScript with tools, resources, and proper configuration |
|
||||
| [TypeScript MCP Server Expert](../chatmodes/typescript-mcp-expert.chatmode.md)<br />[](https://aka.ms/awesome-copilot/install/chatmode?url=vscode%3Achat-mode%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fchatmodes%2Ftypescript-mcp-expert.chatmode.md)<br />[](https://aka.ms/awesome-copilot/install/chatmode?url=vscode-insiders%3Achat-mode%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fchatmodes%2Ftypescript-mcp-expert.chatmode.md) | Chat Mode | Expert assistant for developing Model Context Protocol (MCP) servers in TypeScript [see usage](#typescript-mcp-server-expert) |
|
||||
|
||||
## Collection Usage
|
||||
|
||||
### TypeScript MCP Server Expert
|
||||
|
||||
recommended
|
||||
|
||||
This chat mode provides expert guidance for building MCP servers in TypeScript/Node.js.
|
||||
|
||||
This chat mode is ideal for:
|
||||
- Creating new MCP server projects with TypeScript
|
||||
- Implementing tools, resources, and prompts with zod validation
|
||||
- Setting up HTTP or stdio transports
|
||||
- Debugging schema validation and transport issues
|
||||
- Learning TypeScript MCP best practices
|
||||
- Optimizing server performance and reliability
|
||||
|
||||
To get the best results, consider:
|
||||
- Using the instruction file to set context for TypeScript/Node.js development
|
||||
- Using the prompt to generate initial project structure with proper configuration
|
||||
- Switching to the expert chat mode for detailed implementation help
|
||||
- Specifying whether you need HTTP or stdio transport
|
||||
- Providing details about what tools or functionality you need
|
||||
|
||||
---
|
||||
|
||||
*This collection includes 3 curated items for typescript mcp server development.*
|
||||
228
instructions/typescript-mcp-server.instructions.md
Normal file
228
instructions/typescript-mcp-server.instructions.md
Normal file
@ -0,0 +1,228 @@
|
||||
---
|
||||
description: 'Instructions for building Model Context Protocol (MCP) servers using the TypeScript SDK'
|
||||
applyTo: '**/*.ts, **/*.js, **/package.json'
|
||||
---
|
||||
|
||||
# TypeScript MCP Server Development
|
||||
|
||||
## Instructions
|
||||
|
||||
- Use the **@modelcontextprotocol/sdk** npm package: `npm install @modelcontextprotocol/sdk`
|
||||
- Import from specific paths: `@modelcontextprotocol/sdk/server/mcp.js`, `@modelcontextprotocol/sdk/server/stdio.js`, etc.
|
||||
- Use `McpServer` class for high-level server implementation with automatic protocol handling
|
||||
- Use `Server` class for low-level control with manual request handlers
|
||||
- Use **zod** for input/output schema validation: `npm install zod@3`
|
||||
- Always provide `title` field for tools, resources, and prompts for better UI display
|
||||
- Use `registerTool()`, `registerResource()`, and `registerPrompt()` methods (recommended over older APIs)
|
||||
- Define schemas using zod: `{ inputSchema: { param: z.string() }, outputSchema: { result: z.string() } }`
|
||||
- Return both `content` (for display) and `structuredContent` (for structured data) from tools
|
||||
- For HTTP servers, use `StreamableHTTPServerTransport` with Express or similar frameworks
|
||||
- For local integrations, use `StdioServerTransport` for stdio-based communication
|
||||
- Create new transport instances per request to prevent request ID collisions (stateless mode)
|
||||
- Use session management with `sessionIdGenerator` for stateful servers
|
||||
- Enable DNS rebinding protection for local servers: `enableDnsRebindingProtection: true`
|
||||
- Configure CORS headers and expose `Mcp-Session-Id` for browser-based clients
|
||||
- Use `ResourceTemplate` for dynamic resources with URI parameters: `new ResourceTemplate('resource://{param}', { list: undefined })`
|
||||
- Support completions for better UX using `completable()` wrapper from `@modelcontextprotocol/sdk/server/completable.js`
|
||||
- Implement sampling with `server.server.createMessage()` to request LLM completions from clients
|
||||
- Use `server.server.elicitInput()` to request additional user input during tool execution
|
||||
- Enable notification debouncing for bulk updates: `debouncedNotificationMethods: ['notifications/tools/list_changed']`
|
||||
- Dynamic updates: call `.enable()`, `.disable()`, `.update()`, or `.remove()` on registered items to emit `listChanged` notifications
|
||||
- Use `getDisplayName()` from `@modelcontextprotocol/sdk/shared/metadataUtils.js` for UI display names
|
||||
- Test servers with MCP Inspector: `npx @modelcontextprotocol/inspector`
|
||||
|
||||
## Best Practices
|
||||
|
||||
- Keep tool implementations focused on single responsibilities
|
||||
- Provide clear, descriptive titles and descriptions for LLM understanding
|
||||
- Use proper TypeScript types for all parameters and return values
|
||||
- Implement comprehensive error handling with try-catch blocks
|
||||
- Return `isError: true` in tool results for error conditions
|
||||
- Use async/await for all asynchronous operations
|
||||
- Close database connections and clean up resources properly
|
||||
- Validate input parameters before processing
|
||||
- Use structured logging for debugging without polluting stdout/stderr
|
||||
- Consider security implications when exposing file system or network access
|
||||
- Implement proper resource cleanup on transport close events
|
||||
- Use environment variables for configuration (ports, API keys, etc.)
|
||||
- Document tool capabilities and limitations clearly
|
||||
- Test with multiple clients to ensure compatibility
|
||||
|
||||
## Common Patterns
|
||||
|
||||
### Basic Server Setup (HTTP)
|
||||
```typescript
|
||||
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
||||
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
|
||||
import express from 'express';
|
||||
|
||||
const server = new McpServer({
|
||||
name: 'my-server',
|
||||
version: '1.0.0'
|
||||
});
|
||||
|
||||
const app = express();
|
||||
app.use(express.json());
|
||||
|
||||
app.post('/mcp', async (req, res) => {
|
||||
const transport = new StreamableHTTPServerTransport({
|
||||
sessionIdGenerator: undefined,
|
||||
enableJsonResponse: true
|
||||
});
|
||||
|
||||
res.on('close', () => transport.close());
|
||||
|
||||
await server.connect(transport);
|
||||
await transport.handleRequest(req, res, req.body);
|
||||
});
|
||||
|
||||
app.listen(3000);
|
||||
```
|
||||
|
||||
### Basic Server Setup (stdio)
|
||||
```typescript
|
||||
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
||||
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
||||
|
||||
const server = new McpServer({
|
||||
name: 'my-server',
|
||||
version: '1.0.0'
|
||||
});
|
||||
|
||||
// ... register tools, resources, prompts ...
|
||||
|
||||
const transport = new StdioServerTransport();
|
||||
await server.connect(transport);
|
||||
```
|
||||
|
||||
### Simple Tool
|
||||
```typescript
|
||||
import { z } from 'zod';
|
||||
|
||||
server.registerTool(
|
||||
'calculate',
|
||||
{
|
||||
title: 'Calculator',
|
||||
description: 'Perform basic calculations',
|
||||
inputSchema: { a: z.number(), b: z.number(), op: z.enum(['+', '-', '*', '/']) },
|
||||
outputSchema: { result: z.number() }
|
||||
},
|
||||
async ({ a, b, op }) => {
|
||||
const result = op === '+' ? a + b : op === '-' ? a - b :
|
||||
op === '*' ? a * b : a / b;
|
||||
const output = { result };
|
||||
return {
|
||||
content: [{ type: 'text', text: JSON.stringify(output) }],
|
||||
structuredContent: output
|
||||
};
|
||||
}
|
||||
);
|
||||
```
|
||||
|
||||
### Dynamic Resource
|
||||
```typescript
|
||||
import { ResourceTemplate } from '@modelcontextprotocol/sdk/server/mcp.js';
|
||||
|
||||
server.registerResource(
|
||||
'user',
|
||||
new ResourceTemplate('users://{userId}', { list: undefined }),
|
||||
{
|
||||
title: 'User Profile',
|
||||
description: 'Fetch user profile data'
|
||||
},
|
||||
async (uri, { userId }) => ({
|
||||
contents: [{
|
||||
uri: uri.href,
|
||||
text: `User ${userId} data here`
|
||||
}]
|
||||
})
|
||||
);
|
||||
```
|
||||
|
||||
### Tool with Sampling
|
||||
```typescript
|
||||
server.registerTool(
|
||||
'summarize',
|
||||
{
|
||||
title: 'Text Summarizer',
|
||||
description: 'Summarize text using LLM',
|
||||
inputSchema: { text: z.string() },
|
||||
outputSchema: { summary: z.string() }
|
||||
},
|
||||
async ({ text }) => {
|
||||
const response = await server.server.createMessage({
|
||||
messages: [{
|
||||
role: 'user',
|
||||
content: { type: 'text', text: `Summarize: ${text}` }
|
||||
}],
|
||||
maxTokens: 500
|
||||
});
|
||||
|
||||
const summary = response.content.type === 'text' ?
|
||||
response.content.text : 'Unable to summarize';
|
||||
const output = { summary };
|
||||
return {
|
||||
content: [{ type: 'text', text: JSON.stringify(output) }],
|
||||
structuredContent: output
|
||||
};
|
||||
}
|
||||
);
|
||||
```
|
||||
|
||||
### Prompt with Completion
|
||||
```typescript
|
||||
import { completable } from '@modelcontextprotocol/sdk/server/completable.js';
|
||||
|
||||
server.registerPrompt(
|
||||
'review',
|
||||
{
|
||||
title: 'Code Review',
|
||||
description: 'Review code with specific focus',
|
||||
argsSchema: {
|
||||
language: completable(z.string(), value =>
|
||||
['typescript', 'python', 'javascript', 'java']
|
||||
.filter(l => l.startsWith(value))
|
||||
),
|
||||
code: z.string()
|
||||
}
|
||||
},
|
||||
({ language, code }) => ({
|
||||
messages: [{
|
||||
role: 'user',
|
||||
content: {
|
||||
type: 'text',
|
||||
text: `Review this ${language} code:\n\n${code}`
|
||||
}
|
||||
}]
|
||||
})
|
||||
);
|
||||
```
|
||||
|
||||
### Error Handling
|
||||
```typescript
|
||||
server.registerTool(
|
||||
'risky-operation',
|
||||
{
|
||||
title: 'Risky Operation',
|
||||
description: 'An operation that might fail',
|
||||
inputSchema: { input: z.string() },
|
||||
outputSchema: { result: z.string() }
|
||||
},
|
||||
async ({ input }) => {
|
||||
try {
|
||||
const result = await performRiskyOperation(input);
|
||||
const output = { result };
|
||||
return {
|
||||
content: [{ type: 'text', text: JSON.stringify(output) }],
|
||||
structuredContent: output
|
||||
};
|
||||
} catch (err: unknown) {
|
||||
const error = err as Error;
|
||||
return {
|
||||
content: [{ type: 'text', text: `Error: ${error.message}` }],
|
||||
isError: true
|
||||
};
|
||||
}
|
||||
}
|
||||
);
|
||||
```
|
||||
90
prompts/typescript-mcp-server-generator.prompt.md
Normal file
90
prompts/typescript-mcp-server-generator.prompt.md
Normal file
@ -0,0 +1,90 @@
|
||||
---
|
||||
mode: 'agent'
|
||||
description: 'Generate a complete MCP server project in TypeScript with tools, resources, and proper configuration'
|
||||
---
|
||||
|
||||
# Generate TypeScript MCP Server
|
||||
|
||||
Create a complete Model Context Protocol (MCP) server in TypeScript with the following specifications:
|
||||
|
||||
## Requirements
|
||||
|
||||
1. **Project Structure**: Create a new TypeScript/Node.js project with proper directory structure
|
||||
2. **NPM Packages**: Include @modelcontextprotocol/sdk, zod@3, and either express (for HTTP) or stdio support
|
||||
3. **TypeScript Configuration**: Proper tsconfig.json with ES modules support
|
||||
4. **Server Type**: Choose between HTTP (with Streamable HTTP transport) or stdio-based server
|
||||
5. **Tools**: Create at least one useful tool with proper schema validation
|
||||
6. **Error Handling**: Include comprehensive error handling and validation
|
||||
|
||||
## Implementation Details
|
||||
|
||||
### Project Setup
|
||||
- Initialize with `npm init` and create package.json
|
||||
- Install dependencies: `@modelcontextprotocol/sdk`, `zod@3`, and transport-specific packages
|
||||
- Configure TypeScript with ES modules: `"type": "module"` in package.json
|
||||
- Add dev dependencies: `tsx` or `ts-node` for development
|
||||
- Create proper .gitignore file
|
||||
|
||||
### Server Configuration
|
||||
- Use `McpServer` class for high-level implementation
|
||||
- Set server name and version
|
||||
- Choose appropriate transport (StreamableHTTPServerTransport or StdioServerTransport)
|
||||
- For HTTP: set up Express with proper middleware and error handling
|
||||
- For stdio: use StdioServerTransport directly
|
||||
|
||||
### Tool Implementation
|
||||
- Use `registerTool()` method with descriptive names
|
||||
- Define schemas using zod for input and output validation
|
||||
- Provide clear `title` and `description` fields
|
||||
- Return both `content` and `structuredContent` in results
|
||||
- Implement proper error handling with try-catch blocks
|
||||
- Support async operations where appropriate
|
||||
|
||||
### Resource/Prompt Setup (Optional)
|
||||
- Add resources using `registerResource()` with ResourceTemplate for dynamic URIs
|
||||
- Add prompts using `registerPrompt()` with argument schemas
|
||||
- Consider adding completion support for better UX
|
||||
|
||||
### Code Quality
|
||||
- Use TypeScript for type safety
|
||||
- Follow async/await patterns consistently
|
||||
- Implement proper cleanup on transport close events
|
||||
- Use environment variables for configuration
|
||||
- Add inline comments for complex logic
|
||||
- Structure code with clear separation of concerns
|
||||
|
||||
## Example Tool Types to Consider
|
||||
- Data processing and transformation
|
||||
- External API integrations
|
||||
- File system operations (read, search, analyze)
|
||||
- Database queries
|
||||
- Text analysis or summarization (with sampling)
|
||||
- System information retrieval
|
||||
|
||||
## Configuration Options
|
||||
- **For HTTP Servers**:
|
||||
- Port configuration via environment variables
|
||||
- CORS setup for browser clients
|
||||
- Session management (stateless vs stateful)
|
||||
- DNS rebinding protection for local servers
|
||||
|
||||
- **For stdio Servers**:
|
||||
- Proper stdin/stdout handling
|
||||
- Environment-based configuration
|
||||
- Process lifecycle management
|
||||
|
||||
## Testing Guidance
|
||||
- Explain how to run the server (`npm start` or `npx tsx server.ts`)
|
||||
- Provide MCP Inspector command: `npx @modelcontextprotocol/inspector`
|
||||
- For HTTP servers, include connection URL: `http://localhost:PORT/mcp`
|
||||
- Include example tool invocations
|
||||
- Add troubleshooting tips for common issues
|
||||
|
||||
## Additional Features to Consider
|
||||
- Sampling support for LLM-powered tools
|
||||
- User input elicitation for interactive workflows
|
||||
- Dynamic tool registration with enable/disable capabilities
|
||||
- Notification debouncing for bulk updates
|
||||
- Resource links for efficient data references
|
||||
|
||||
Generate a complete, production-ready MCP server with comprehensive documentation, type safety, and error handling.
|
||||
Loading…
x
Reference in New Issue
Block a user