mirror of
https://github.com/samanhappy/mcphub.git
synced 2025-12-23 18:29:21 -05:00
initialize project
This commit is contained in:
2
.env.example
Normal file
2
.env.example
Normal file
@@ -0,0 +1,2 @@
|
||||
PORT=3000
|
||||
NODE_ENV=development
|
||||
19
.eslintrc.json
Normal file
19
.eslintrc.json
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"extends": [
|
||||
"eslint:recommended",
|
||||
"plugin:@typescript-eslint/recommended"
|
||||
],
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 2020,
|
||||
"sourceType": "module"
|
||||
},
|
||||
"env": {
|
||||
"node": true,
|
||||
"es6": true,
|
||||
"jest": true
|
||||
},
|
||||
"rules": {
|
||||
"no-console": "off"
|
||||
}
|
||||
}
|
||||
26
.gitignore
vendored
Normal file
26
.gitignore
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
# dependencies
|
||||
/node_modules
|
||||
/.pnp
|
||||
.pnp.js
|
||||
|
||||
# production
|
||||
/dist
|
||||
|
||||
# env files
|
||||
.env
|
||||
.env.local
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
|
||||
# logs
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
|
||||
# misc
|
||||
.DS_Store
|
||||
.idea/
|
||||
.vscode/
|
||||
*.log
|
||||
coverage/
|
||||
7
.prettierrc
Normal file
7
.prettierrc
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"semi": true,
|
||||
"trailingComma": "all",
|
||||
"singleQuote": true,
|
||||
"printWidth": 100,
|
||||
"tabWidth": 2
|
||||
}
|
||||
49
README.md
Normal file
49
README.md
Normal file
@@ -0,0 +1,49 @@
|
||||
# Server Insure
|
||||
|
||||
A TypeScript server for insurance services.
|
||||
|
||||
## Requirements
|
||||
|
||||
- Node.js (v14+)
|
||||
- npm or yarn
|
||||
|
||||
## Installation
|
||||
|
||||
1. Clone the repository
|
||||
2. Install dependencies:
|
||||
```bash
|
||||
npm install
|
||||
```
|
||||
3. Create a `.env` file based on `.env.example`
|
||||
4. Run the development server:
|
||||
```bash
|
||||
npm run dev
|
||||
```
|
||||
|
||||
## Available Scripts
|
||||
|
||||
- `npm run build` - Compiles TypeScript to JavaScript
|
||||
- `npm run start` - Starts the server from compiled JavaScript
|
||||
- `npm run dev` - Starts the development server with hot reloading
|
||||
- `npm run lint` - Runs ESLint to check for code quality
|
||||
- `npm run format` - Formats code using Prettier
|
||||
- `npm run test` - Runs tests using Jest
|
||||
|
||||
## Project Structure
|
||||
|
||||
```
|
||||
mcphub/
|
||||
├── src/ # Source code
|
||||
│ ├── routes/ # API routes
|
||||
│ └── index.ts # Entry point
|
||||
├── dist/ # Compiled JavaScript (generated)
|
||||
├── .env # Environment variables (create from .env.example)
|
||||
├── package.json # Project dependencies and scripts
|
||||
└── tsconfig.json # TypeScript configuration
|
||||
```
|
||||
|
||||
## API Endpoints
|
||||
|
||||
- GET /api/insurance - Get all insurance policies
|
||||
- GET /api/insurance/:id - Get a specific insurance policy
|
||||
- POST /api/insurance - Create a new insurance policy
|
||||
10
jest.config.js
Normal file
10
jest.config.js
Normal file
@@ -0,0 +1,10 @@
|
||||
module.exports = {
|
||||
preset: 'ts-jest',
|
||||
testEnvironment: 'node',
|
||||
roots: ['<rootDir>/src'],
|
||||
transform: {
|
||||
'^.+\\.tsx?$': 'ts-jest',
|
||||
},
|
||||
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$',
|
||||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
|
||||
};
|
||||
6431
package-lock.json
generated
Normal file
6431
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
40
package.json
Normal file
40
package.json
Normal file
@@ -0,0 +1,40 @@
|
||||
{
|
||||
"name": "mcphub",
|
||||
"version": "0.0.1",
|
||||
"description": "A hub server for mcp servers",
|
||||
"main": "dist/index.js",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"start": "node dist/index.js",
|
||||
"dev": "tsx watch src/index.ts",
|
||||
"lint": "eslint . --ext .ts",
|
||||
"format": "prettier --write \"src/**/*.ts\"",
|
||||
"test": "jest"
|
||||
},
|
||||
"keywords": [
|
||||
"typescript",
|
||||
"server"
|
||||
],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@modelcontextprotocol/sdk": "^1.8.0",
|
||||
"dotenv": "^16.3.1",
|
||||
"express": "^4.18.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/express": "^4.17.21",
|
||||
"@types/jest": "^29.5.5",
|
||||
"@types/node": "^20.8.2",
|
||||
"@typescript-eslint/eslint-plugin": "^6.7.4",
|
||||
"@typescript-eslint/parser": "^6.7.4",
|
||||
"eslint": "^8.50.0",
|
||||
"jest": "^29.7.0",
|
||||
"prettier": "^3.0.3",
|
||||
"ts-jest": "^29.1.1",
|
||||
"ts-node-dev": "^2.0.0",
|
||||
"tsx": "^4.7.0",
|
||||
"typescript": "^5.2.2"
|
||||
}
|
||||
}
|
||||
4851
pnpm-lock.yaml
generated
Normal file
4851
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
47
src/index.ts
Normal file
47
src/index.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import express, { Request, Response } from 'express';
|
||||
import dotenv from 'dotenv';
|
||||
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
||||
import { SSEServerTransport } from '@modelcontextprotocol/sdk/server/sse.js';
|
||||
import { registerAllTools } from './server.js';
|
||||
|
||||
dotenv.config();
|
||||
|
||||
const server = new McpServer({
|
||||
name: 'mcphub',
|
||||
version: '0.0.1',
|
||||
});
|
||||
|
||||
// Register all MCP tools from the modular structure
|
||||
registerAllTools(server);
|
||||
|
||||
const app = express();
|
||||
const PORT = process.env.PORT || 3000;
|
||||
|
||||
// to support multiple simultaneous connections we have a lookup object from sessionId to transport
|
||||
const transports: { [sessionId: string]: SSEServerTransport } = {};
|
||||
|
||||
app.get('/sse', async (_: Request, res: Response) => {
|
||||
const transport = new SSEServerTransport('/messages', res);
|
||||
transports[transport.sessionId] = transport;
|
||||
res.on('close', () => {
|
||||
delete transports[transport.sessionId];
|
||||
});
|
||||
await server.connect(transport);
|
||||
});
|
||||
|
||||
app.post('/messages', async (req: Request, res: Response) => {
|
||||
const sessionId = req.query.sessionId as string;
|
||||
const transport = transports[sessionId];
|
||||
if (transport) {
|
||||
await transport.handlePostMessage(req, res);
|
||||
} else {
|
||||
console.error(`No transport found for sessionId: ${sessionId}`);
|
||||
res.status(400).send('No transport found for sessionId');
|
||||
}
|
||||
});
|
||||
|
||||
app.listen(PORT, () => {
|
||||
console.log(`Server is running on port ${PORT}`);
|
||||
});
|
||||
|
||||
export default app;
|
||||
55
src/server.ts
Normal file
55
src/server.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
||||
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
||||
import { SSEClientTransport } from '@modelcontextprotocol/sdk/client/sse.js';
|
||||
import { ZodType, ZodRawShape } from 'zod';
|
||||
|
||||
const transport = new SSEClientTransport(new URL('http://localhost:3001/sse'));
|
||||
|
||||
const client = new Client(
|
||||
{
|
||||
name: 'example-client',
|
||||
version: '1.0.0',
|
||||
},
|
||||
{
|
||||
capabilities: {
|
||||
prompts: {},
|
||||
resources: {},
|
||||
tools: {},
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
export const registerAllTools = async (server: McpServer) => {
|
||||
await client.connect(transport);
|
||||
const tools = await client.listTools();
|
||||
for (const tool of tools.tools) {
|
||||
await server.tool(
|
||||
tool.name,
|
||||
tool.description || '',
|
||||
cast(tool.inputSchema.properties),
|
||||
async (params) => {
|
||||
const result = await client.callTool({
|
||||
name: tool.name,
|
||||
arguments: params,
|
||||
});
|
||||
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
||||
},
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
function cast(inputSchema: unknown): ZodRawShape {
|
||||
if (typeof inputSchema !== 'object' || inputSchema === null) {
|
||||
throw new Error('Invalid input schema');
|
||||
}
|
||||
|
||||
const castedSchema = inputSchema as ZodRawShape;
|
||||
|
||||
for (const key in castedSchema) {
|
||||
if (castedSchema[key] instanceof ZodType) {
|
||||
castedSchema[key] = castedSchema[key].optional() as ZodType;
|
||||
}
|
||||
}
|
||||
|
||||
return castedSchema;
|
||||
}
|
||||
17
tsconfig.json
Normal file
17
tsconfig.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2020",
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"outDir": "./dist",
|
||||
"rootDir": "./src",
|
||||
"strict": true,
|
||||
"esModuleInterop": true,
|
||||
"skipLibCheck": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"resolveJsonModule": true,
|
||||
"sourceMap": true
|
||||
},
|
||||
"include": ["src/**/*"],
|
||||
"exclude": ["node_modules", "**/*.test.ts", "dist"]
|
||||
}
|
||||
Reference in New Issue
Block a user