Thank you for your interest in contributing to the MCP Template Node project! This document provides guidelines and instructions for contributing.
-
Prerequisites
- Node.js 18 or later
- npm or yarn (we use yarn as the default)
- Git
-
Clone and Install
git clone https://github.com/yourusername/mcp-template-node.git cd mcp-template-node yarn install
-
Development Scripts
yarn build
- Build the projectyarn dev
- Watch mode for developmentyarn lint
- Run ESLintyarn lint:fix
- Fix ESLint issuesyarn test
- Run testsyarn test:watch
- Run tests in watch modeyarn inspector
- Run MCP Inspector for testingyarn clean
- Clean build artifactsyarn start
- Run the built server
cmd/ # Go example code for testing
├── example/ # Simple Go application for testing tools
src/
├── errors/ # Custom error classes
├── tools/ # MCP tool implementations
│ ├── goTools.ts # Go tools for LLM
│ └── noteTools.ts # Example note tools
├── types/ # TypeScript type definitions
└── index.ts # Main server entry point
-
TypeScript
- Use strict mode
- Add explicit function return types
- Use interfaces for object types
- Document public APIs with JSDoc comments
-
Code Style
- Use single quotes for strings
- No semicolons (except where required)
- 2-space indentation
- Follow ESLint rules defined in
eslint.config.mjs
- We use ESLint but not Prettier
-
Error Handling
- Use custom error classes for domain-specific errors
- Include error codes for better error identification
- Handle all possible error cases
- Provide clear error messages
-
Go Tool Implementation
- Tool commands should be executable in any Go environment
- Handle command output uniformly across tools
- Properly parse both stdout and stderr
- Return appropriate exit codes and error messages
- Handle command failures gracefully
-
MCP Components Implementation
Tools:
-
Keep tools focused and single-purpose
-
Use Zod for input validation and type safety
-
Follow the MCP response format
-
Include comprehensive error handling
-
Return appropriate content types
-
Example:
server.tool( 'tool_name', { parameter1: z.string().min(1), parameter2: z.number().min(0) }, async ({ parameter1, parameter2 }) => { // Implementation return { content: [{ type: 'text', text: 'Result' }] } } )
Resources:
-
Treat resources as read-only data providers
-
Use ResourceTemplate for parameterized resources
-
Return consistent formats
-
Example:
server.resource( 'resource_name', new ResourceTemplate('protocol://{param}', { list: undefined }), async (uri, { param }) => ({ contents: [{ uri: uri.href, text: `Data for ${param}` }] }) )
Prompts:
-
Keep prompts simple and focused
-
Use message role 'user' for most cases
-
Example:
server.prompt( 'prompt_name', { parameter: z.string() }, ({ parameter }) => ({ messages: [{ role: 'user', content: { type: 'text', text: `Process this: ${parameter}` } }] }) )
-
-
Testing
- Write unit tests for all tools
- Mock the MCP server for testing
- Test both success and error cases
- Test input validation
- Use Vitest for testing
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Make your changes
- Run linting and tests (
yarn lint && yarn test
) - Commit using conventional commits format
- Push to your fork
- Create a Pull Request
We use the Conventional Commits specification for commit messages:
<type>(<scope>): <description>
[optional body]
[optional footer]
Types:
feat
: New featurefix
: Bug fixdocs
: Documentationstyle
: Formattingrefactor
: Code restructuringtest
: Adding testschore
: Maintenance
Example:
feat(tools): add new note search tool
Implements fuzzy search for notes using title and content.
-
Tool Design
- Tools should perform one action or a closely related set of actions
- Validate inputs before processing
- Return clear success or error responses
- Provide descriptive names that indicate the action
-
Go Tool Design
- Use consistent parameter naming and defaults
- Handle process output consistently
- Provide clear error messages for command failures
- Include documentation for each Go tool
-
Error Handling
- Use custom error classes
- Return user-friendly error messages
- Include error codes for programmatic handling
- Catch and handle expected exceptions
-
Security Considerations
- Validate all inputs
- Avoid using
eval()
in production code - Implement rate limiting for tools in production
- Consider authentication for production deployments
Feel free to open an issue for:
- Bug reports
- Feature requests
- Questions about the codebase
- Suggestions for improvements
By contributing to MCP Golang, you agree that your contributions will be licensed under the project's MIT License.