Skip to content

Commit a8dc6cf

Browse files
authored
Initial commit
0 parents  commit a8dc6cf

36 files changed

+11380
-0
lines changed

.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
PORT=8401

.github/workflows/build.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: build
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
build:
10+
if: github.repository == 'my-mcp-hub/node-mcp-server'
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v4
15+
with:
16+
fetch-depth: 0
17+
18+
- name: Install Node
19+
uses: actions/setup-node@v4
20+
with:
21+
node-version: 22
22+
cache: npm
23+
24+
- name: Install Package
25+
run: npm i
26+
27+
- name: Build Package
28+
run: npm run build
29+
30+
- name: Test Package
31+
run: npm run coverage
32+
33+
- name: Coveralls
34+
uses: coverallsapp/github-action@v2

.github/workflows/npm-publish.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: npm-publish
2+
3+
on:
4+
release:
5+
types: [created]
6+
7+
jobs:
8+
build:
9+
if: github.repository == 'my-mcp-hub/node-mcp-server'
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: read
13+
id-token: write
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0
19+
20+
- name: Install Node
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version: 22
24+
registry-url: https://registry.npmjs.org/
25+
cache: npm
26+
27+
- name: Install Package
28+
run: npm i
29+
30+
- name: Build Package
31+
run: npm run build
32+
33+
- name: Publish NPM Package
34+
run: npm publish
35+
env:
36+
NODE_AUTH_TOKEN: ${{secrets.npm_token}}

.gitignore

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
.DS_Store
2+
.idea/
3+
# Logs
4+
logs
5+
*.log
6+
npm-debug.log*
7+
yarn-debug.log*
8+
yarn-error.log*
9+
lerna-debug.log*
10+
11+
# Diagnostic reports (https://nodejs.org/api/report.html)
12+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
13+
14+
# Runtime data
15+
pids
16+
*.pid
17+
*.seed
18+
*.pid.lock
19+
20+
# Directory for instrumented libs generated by jscoverage/JSCover
21+
lib-cov
22+
23+
# Coverage directory used by tools like istanbul
24+
coverage
25+
*.lcov
26+
27+
# nyc test coverage
28+
.nyc_output
29+
30+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
31+
.grunt
32+
33+
# Bower dependency directory (https://bower.io/)
34+
bower_components
35+
36+
# node-waf configuration
37+
.lock-wscript
38+
39+
# Compiled binary addons (https://nodejs.org/api/addons.html)
40+
build/Release
41+
42+
# Dependency directories
43+
node_modules/
44+
jspm_packages/
45+
46+
# TypeScript v1 declaration files
47+
typings/
48+
49+
# TypeScript cache
50+
*.tsbuildinfo
51+
52+
# Optional npm cache directory
53+
.npm
54+
55+
# Optional eslint cache
56+
.eslintcache
57+
58+
# Microbundle cache
59+
.rpt2_cache/
60+
.rts2_cache_cjs/
61+
.rts2_cache_es/
62+
.rts2_cache_umd/
63+
64+
# Optional REPL history
65+
.node_repl_history
66+
67+
# Output of 'npm pack'
68+
*.tgz
69+
70+
# Yarn Integrity file
71+
.yarn-integrity
72+
73+
# dotenv environment variables file
74+
#.env
75+
.env.test
76+
77+
# parcel-bundler cache (https://parceljs.org/)
78+
.cache
79+
80+
# Next.js build output
81+
.next
82+
83+
# Nuxt.js build / generate output
84+
.nuxt
85+
dist
86+
87+
# Gatsby files
88+
.cache/
89+
# Comment in the public line in if your project uses Gatsby and *not* Next.js
90+
# https://nextjs.org/blog/next-9-1#public-directory-support
91+
# public
92+
93+
# vuepress build output
94+
.vuepress/dist
95+
96+
# Serverless directories
97+
.serverless/
98+
99+
# FuseBox cache
100+
.fusebox/
101+
102+
# DynamoDB Local files
103+
.dynamodb/
104+
105+
# TernJS port file
106+
.tern-port
107+
108+
/docs/.vitepress/cache/
109+
110+
stats.html
111+
112+
build/

.husky/commit-msg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
npx --no-install commitlint --edit $1

.husky/pre-commit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
npx lint-staged

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v22

.prettierrc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"tabWidth": 2,
3+
"printWidth": 120,
4+
"useTabs": false,
5+
"semi": false,
6+
"singleQuote": true,
7+
"trailingComma": "all",
8+
"bracketSpacing": true,
9+
"jsxBracketSameLine": false,
10+
"arrowParens": "avoid"
11+
}

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 my-mcp-hub
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Node.js MCP Server Template
2+
3+
A Model Context Protocol (MCP) server template for Node.js applications. This template provides a foundation for building MCP-compatible servers with support for multiple transport protocols.
4+
5+
## Features
6+
- Multiple Transport Protocols :
7+
8+
- Standard I/O (stdio) for command-line interfaces
9+
- HTTP Streamable transport for web applications
10+
- Server-Sent Events (SSE) for real-time updates
11+
- TypeScript Support : Built with TypeScript for type safety and better developer experience
12+
- Development Tools :
13+
14+
- Hot reloading during development
15+
- Integration with MCP Inspector for debugging
16+
- ESLint and Prettier for code quality
17+
- Husky and lint-staged for Git hooks
18+
- Extensible Tool System : Easy registration of custom MCP tools
19+
20+
## Prerequisites
21+
- Node.js (latest LTS version recommended)
22+
- npm or yarn
23+
24+
## Installation
25+
26+
```bash
27+
npm install
28+
```
29+
30+
## Development
31+
```bash
32+
# Start development server with stdio transport
33+
npm run dev
34+
35+
# Start development server with web transport
36+
npm run dev:web
37+
```
38+
39+
When using dev:web , the server will be available at:
40+
41+
- Streamable HTTP endpoint: http://localhost:8401/mcp
42+
- SSE endpoint: http://localhost:8401/sse
43+
44+
## Building
45+
```bash
46+
npm run build
47+
```
48+
The build output will be in the build directory.
49+
50+
## Usage
51+
### Command Line
52+
```bash
53+
# Start with stdio transport (default)
54+
node build/index.js
55+
56+
# Start with web transport
57+
node build/index.js web --port 8401
58+
```
59+
### Adding Custom Tools
60+
Custom tools can be added in the src/tools/index.ts file:
61+
62+
```ts
63+
server.registerTool(
64+
'YourToolName',
65+
{
66+
title: 'Your Tool Name',
67+
description: 'Tool description',
68+
inputSchema: {
69+
param1: z.string().describe('Parameter description'),
70+
},
71+
},
72+
({ param1 }) => {
73+
// Implement tool logic
74+
return {
75+
content: [
76+
{
77+
type: 'text',
78+
text: `Your tool response: ${param1}`,
79+
},
80+
],
81+
}
82+
},
83+
)
84+
```
85+
86+
## Environment Variables
87+
- PORT : Specify the port for web transport (default: 8401)
88+
- NODE_ENV : Set to production for production builds or local for development
89+
90+
## License
91+
[MIT](LICENSE)

0 commit comments

Comments
 (0)