MCP server agent

A generic, modular server for implementing the Model Context Protocol (MCP).

by profullstack·ISC license·★ 45 Stars on the repo·GitHub ↗

Files of MCP server

profullstack/master1 file
README.md
Show the full text575 lines

MCP Server (Model Context Protocol)

Node

A generic, modular server for implementing the Model Context Protocol (MCP). This server provides a framework for controlling and interacting with various models through a standardized API.

Crypto Payment

Hosted deployment

A hosted deployment is available on Fronteir AI.

Features

  • Modular architecture for easy extension
  • Dynamic module loading
  • Core model management functionality
  • Standardized API for model context
  • Simple configuration system
  • Logging utilities
  • Enhanced module structure with proper separation of concerns
  • Package.json support for modules with dependency management
  • Comprehensive testing infrastructure with Mocha and Chai
  • Powerful module search functionality
  • Module metadata display in API responses
  • Integration with real AI model providers (OpenAI, Stability AI, Anthropic, Hugging Face)
  • Support for text generation, image generation, and speech-to-text models
  • Streaming inference support for compatible models

Getting Started

Prerequisites
  • Node.js 18.x or higher
  • pnpm 10.x or higher

This project uses ES Modules (ESM) exclusively. All imports use the import syntax rather than require().

Installation
# Clone the repository
git clone https://github.com/yourusername/mcp-server.git
cd mcp-server

# Install dependencies
pnpm install
Running the Server
# Install dependencies
pnpm install

# Start the server
pnpm start

# Start the server in development mode (with auto-reload)
pnpm dev

The server will start on http://localhost:3000 by default.

Configuration

Copy the sample environment file and edit it with your API keys:

# Copy the sample environment file
cp sample.env .env

# Edit the file with your favorite editor
nano .env

At minimum, you'll need to add API keys for the model providers you want to use:

# OpenAI API (for GPT-4 and Whisper)
OPENAI_API_KEY=your_openai_api_key_here

# Stability AI API (for Stable Diffusion)
STABILITY_API_KEY=your_stability_api_key_here

# Anthropic API (for Claude models)
ANTHROPIC_API_KEY=your_anthropic_api_key_here

You can get these API keys from:

Security

The server has no global authentication layer, so anything that can reach the port can call any module route. Modules that touch the filesystem or issue outbound requests are constrained as follows.

Module tokens. Routes with side effects accept a token via Authorization: Bearer <token> or X-API-Key: <token>. When the variable is unset the routes stay open and a warning is logged at startup.

Variable Guards
SCANNER_API_TOKEN /scanner/scan, /scanner/reports/:id/export, /tools/scanner
README_BADGES_API_TOKEN /readme-badges/update, /readme-badges/detect, /tools/readme-badges

Path containment. readme-badges resolves readmePath and rootDir against README_BADGES_ROOT (default: the working directory) and refuses anything that escapes it, targets a non-markdown file, or reaches outside via a symlink. scanner confines exports to its reports directory the same way.

Outbound request allowlists. Modules that fetch caller-named URLs reject loopback, link-local (cloud metadata), RFC1918, CGNAT and other non-public addresses, resolve hostnames and check every returned address, and re-validate each redirect hop. Where a module talks to one known service, the host is also allowlisted:

Variable Extends the allowlist for
CONVERT2DOC_ALLOWED_HOSTS convert2doc baseUrl (default: convert2doc.com)
CRAIGSLIST_ALLOWED_HOSTS /craigslist/details (default: *.craigslist.org)

Cross-origin requests. CSRF_PROTECTION_ENABLED (default true) rejects state-changing requests that carry a foreign Origin header, so a malicious web page cannot drive a browser at a localhost-bound server. Clients that send no Origin — curl, MCP clients, server-to-server calls — are unaffected. List trusted browser origins in CORS_ORIGINS.

Run the server behind an authenticating reverse proxy if it is exposed beyond localhost.

Testing the Server

The repository includes comprehensive testing using Mocha and Chai:

# Run all tests
pnpm test

# Run only module tests
pnpm test:modules

# Run all tests (both core and modules)
pnpm test:all

The testing infrastructure includes:

  1. Core server tests for module loading, routing, and other core functionality
  2. Module-specific tests for each module's functionality
  3. Support for ES modules in tests
  4. Mocking and stubbing utilities with Sinon

Tests are organized in a structured way:

  • Core tests in /test/core/
  • Module tests in each module's test/ directory

This comprehensive testing ensures code quality and makes it easier to detect regressions when making changes.

Pre-commit Hooks

The repository includes pre-commit hooks using Husky and lint-staged:

# The hooks are automatically installed when you run
pnpm install

The pre-commit hooks:

  1. Run ESLint on JavaScript files
  2. Run Prettier on all staged files

This ensures that all code committed to the repository follows coding standards and maintains code quality. The test suite is continuously being improved to provide better coverage and reliability, and will be enabled in the pre-commit hook once it's more stable.

Docker Support

The repository includes Docker support for easy containerization and deployment:

# Build and run with Docker
docker build -t mcp-server .
docker run -p 3000:3000 mcp-server

# Or use Docker Compose
docker-compose up

The Docker configuration:

  • Uses Node.js 20 Alpine as the base image
  • Exposes port 3000
  • Mounts the modules directory as a volume for easy module management
  • Includes health checks

Standard MCP Methods

The MCP server implements a standardized set of methods that all MCP servers should provide:

Server Information
  • GET / - Basic server information
  • GET /status - Detailed server status
  • GET /health - Health check endpoint
  • GET /metrics - Server metrics
Model Management
  • GET /models - List available models
  • GET /model/:modelId - Get model information
  • POST /model/:modelId/activate - Activate a specific model
  • POST /model/deactivate - Deactivate the current model
  • GET /model/active - Get information about the active model
Inference
  • POST /model/infer - Perform inference with the active model
  • POST /model/:modelId/infer - Perform inference with a specific model
Supported Models

The MCP server supports the following model types:

Model Type Provider Capabilities Example IDs
GPT Models OpenAI Text generation gpt-4, gpt-3.5-turbo
Whisper OpenAI Speech-to-text whisper, whisper-1
Stable Diffusion Stability AI Image generation stable-diffusion-xl-1024-v1-0
Claude Models Anthropic Text generation claude-3-opus, claude-3-sonnet
Custom Models Hugging Face Various (any Hugging Face model ID)
Inference Examples

Text generation with GPT-4:

# Activate the model
curl -X POST http://localhost:3000/model/gpt-4/activate \
  -H "Content-Type: application/json" \
  -d '{"config": {"temperature": 0.7}}'

# Perform inference
curl -X POST http://localhost:3000/model/infer \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "Explain quantum computing in simple terms",
    "temperature": 0.5,
    "max_tokens": 200
  }'

Image generation with Stable Diffusion:

# Activate the model
curl -X POST http://localhost:3000/model/stable-diffusion/activate \
  -H "Content-Type: application/json" \
  -d '{}'

# Generate an image
curl -X POST http://localhost:3000/model/infer \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "A beautiful sunset over mountains",
    "height": 1024,
    "width": 1024,
    "steps": 30
  }'

Streaming text generation:

# Enable streaming
curl -X POST http://localhost:3000/model/infer \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "Write a short story about a robot",
    "stream": true
  }'
Module Management
  • GET /modules - List installed modules
  • GET /modules/:moduleId - Get module information
  • GET /modules/search/:query - Search modules by any field in their package.json or metadata
Tools and Resources
  • GET /tools - List available tools
  • GET /resources - List available resources

For detailed information about these methods, see MCP Standard Methods.

Configuration

Configuration is loaded from environment variables and stored in src/core/config.js. The easiest way to configure the server is to edit the .env file in the project root.

Environment Variables

Key environment variables include:

Variable Description Default
PORT Server port 3000
HOST Server host localhost
NODE_ENV Environment (development/production) development
OPENAI_API_KEY OpenAI API key (required for OpenAI models)
STABILITY_API_KEY Stability AI API key (required for Stable Diffusion)
ANTHROPIC_API_KEY Anthropic API key (required for Claude models)
HUGGINGFACE_API_KEY Hugging Face API key (required for Hugging Face models)

See sample.env for a complete list of configuration options.

Examples

The repository includes several examples to help you get started:

  • Client Example: examples/client.js demonstrates how to interact with the MCP server from a client application.
  • Custom Module Example: examples/custom-module/ shows how to create a custom module that adds a calculator tool to the server.

To run the client example:

node examples/client.js

To use the custom module example, copy it to the modules directory:

cp -r examples/custom-module mcp_modules/calculator

Creating Modules

Modules are the primary way to extend the MCP server. Each module is a self-contained package that can add new functionality to the server.

Module Structure

Modules now follow an enhanced structure with better organization:

mcp_modules/your-module/
├── assets/          # Static assets (images, CSS, etc.)
├── docs/            # Documentation files
├── examples/        # Example usage
├── src/             # Source code
│   ├── controller.js  # HTTP route handlers
│   ├── service.js     # Business logic
│   └── utils.js       # Utility functions
├── test/            # Test files
│   ├── controller.test.js
│   └── service.test.js
├── index.js         # Main module file with register function
├── package.json     # Module metadata, dependencies, and scripts
└── README.md        # Module documentation

Each module should include a package.json file with:

  • Name, version, description
  • Author and license information
  • Dependencies and dev dependencies
  • Scripts (especially for testing)
  • Keywords and other metadata

This structure provides better separation of concerns, makes testing easier, and improves module discoverability.

Module Implementation

The main module file (index.js) must export a register function that will be called when the module is loaded:

/**
 * Register this module with the Hono app
 * @param {import('hono').Hono} app - The Hono app instance
 */
export async function register(app) {
  // Register routes, middleware, etc.
  app.get('/your-module/endpoint', c => {
    return c.json({ message: 'Your module is working!' });
  });
}

// Optional: Export module metadata
export const metadata = {
  name: 'Your Module',
  version: '1.0.0',
  description: 'Description of your module',
  author: 'Your Name',
};
Example Modules
  • A simple example module is provided in mcp_modules/example/ to demonstrate how to create a module.
  • A more complex example with a calculator tool is provided in examples/custom-module/.
  • A health check module is provided in mcp_modules/health-check/ for system monitoring.
  • A template for creating new modules is available in mcp_modules/template/.
Creating New Modules

You can create a new module using the provided script:

# Create a new module
pnpm create-module

# Or with a module name
pnpm create-module my-module

The script will:

  1. Create a new module directory in mcp_modules/
  2. Copy the template files
  3. Replace placeholders with your module information
  4. Provide next steps for implementing your module

The MCP server includes a powerful search functionality that allows you to find modules based on any information in their package.json or metadata.

Search Endpoints
  • GET /modules/search/:query - Search for modules containing the specified query string in any field
Search Examples
# Find modules by name or description
curl http://localhost:3000/modules/search/craigslist

# Find modules by dependency
curl http://localhost:3000/modules/search/jsdom

# Find modules by keyword
curl http://localhost:3000/modules/search/mcp

# Find modules by author
curl http://localhost:3000/modules/search/"MCP Server Team"

# Find modules by license
curl http://localhost:3000/modules/search/ISC
JavaScript Example
// Function to search modules by any field
async function searchModules(query) {
  const response = await fetch(`http://localhost:3000/modules/search/${query}`);
  const data = await response.json();

  console.log(`Found ${data.count} modules matching "${query}":`);
  data.results.forEach(module => {
    console.log(`- ${module.name} (${module.directoryName}): ${module.description}`);
  });

  return data.results;
}

The search is comprehensive and will find matches in any field, including nested objects like dependencies, keywords, and other metadata.

Model Providers

The MCP server integrates with several AI model providers:

OpenAI

OpenAI provides GPT models for text generation and Whisper for speech-to-text:

// Text generation example
const response = await fetch('http://localhost:3000/model/infer', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    prompt: 'Write a poem about artificial intelligence',
    temperature: 0.7,
    max_tokens: 200,
  }),
});

// Speech-to-text example (requires multipart form data)
const formData = new FormData();
formData.append('file', audioFile);
formData.append('model', 'whisper-1');
formData.append('language', 'en');

const response = await fetch('http://localhost:3000/model/whisper/infer', {
  method: 'POST',
  body: formData,
});
Stability AI

Stability AI provides Stable Diffusion for image generation:

const response = await fetch('http://localhost:3000/model/infer', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    prompt: 'A photorealistic image of a futuristic city',
    height: 1024,
    width: 1024,
    steps: 30,
    cfg_scale: 7,
  }),
});

// The response includes base64-encoded images
const result = await response.json();
const imageBase64 = result.response[0].base64;
Anthropic

Anthropic provides Claude models for text generation:

const response = await fetch('http://localhost:3000/model/infer', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    prompt: 'Explain how neural networks work',
    temperature: 0.5,
    max_tokens: 300,
  }),
});
Hugging Face

Hugging Face provides access to thousands of open-source models:

const response = await fetch('http://localhost:3000/model/custom-model-name/infer', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    prompt: 'Input for the model',
    parameters: {
      // Model-specific parameters
    },
  }),
});

Documentation

  • MCP Standard Methods: Documentation of the standard methods that all MCP servers should implement.
  • MCP Interface: TypeScript interface definitions for the MCP protocol.
  • Architecture: Overview of the MCP server architecture.

License

ISC

1# MCP Server (Model Context Protocol)
2 
3<!-- readme-badges:start -->
4 
5[![Node](https://img.shields.io/badge/Node-6DA55F.svg?logo=node.js&logoColor=fff&style=for-the-badge)](https://github.com/profullstack/mcp-server)
6 
7<!-- readme-badges:end -->
8 
9A generic, modular server for implementing the Model Context Protocol (MCP). This server provides a framework for controlling and interacting with various models through a standardized API.
10 
11[![Crypto Payment](https://paybadge.profullstack.com/badge.svg)](https://paybadge.profullstack.com/?tickers=btc%2Ceth%2Csol%2Cusdc)
12 
13## Hosted deployment
14 
15A hosted deployment is available on [Fronteir AI](https://fronteir.ai/mcp/profullstack-mcp-server).
16 
17## Features
18 
19- Modular architecture for easy extension
20- Dynamic module loading
21- Core model management functionality
22- Standardized API for model context
23- Simple configuration system
24- Logging utilities
25- Enhanced module structure with proper separation of concerns
26- Package.json support for modules with dependency management
27- Comprehensive testing infrastructure with Mocha and Chai
28- Powerful module search functionality
29- Module metadata display in API responses
30- Integration with real AI model providers (OpenAI, Stability AI, Anthropic, Hugging Face)
31- Support for text generation, image generation, and speech-to-text models
32- Streaming inference support for compatible models
33 
34## Getting Started
35 
36### Prerequisites
37 
38- Node.js 18.x or higher
39- pnpm 10.x or higher
40 
41This project uses ES Modules (ESM) exclusively. All imports use the `import` syntax rather than `require()`.
42 
43### Installation
44 
45```bash
46# Clone the repository
47git clone https://github.com/yourusername/mcp-server.git
48cd mcp-server
49 
50# Install dependencies
51pnpm install
52```
53 
54### Running the Server
55 
56```bash
57# Install dependencies
58pnpm install
59 
60# Start the server
61pnpm start
62 
63# Start the server in development mode (with auto-reload)
64pnpm dev
65```
66 
67The server will start on http://localhost:3000 by default.
68 
69### Configuration
70 
71Copy the sample environment file and edit it with your API keys:
72 
73```bash
74# Copy the sample environment file
75cp sample.env .env
76 
77# Edit the file with your favorite editor
78nano .env
79```
80 
81At minimum, you'll need to add API keys for the model providers you want to use:
82 
83```
84# OpenAI API (for GPT-4 and Whisper)
85OPENAI_API_KEY=your_openai_api_key_here
86 
87# Stability AI API (for Stable Diffusion)
88STABILITY_API_KEY=your_stability_api_key_here
89 
90# Anthropic API (for Claude models)
91ANTHROPIC_API_KEY=your_anthropic_api_key_here
92```
93 
94You can get these API keys from:
95 
96- OpenAI: https://platform.openai.com/api-keys
97- Stability AI: https://platform.stability.ai/account/keys
98- Anthropic: https://console.anthropic.com/settings/keys
99 
100### Security
101 
102The server has no global authentication layer, so anything that can reach the
103port can call any module route. Modules that touch the filesystem or issue
104outbound requests are constrained as follows.
105 
106**Module tokens.** Routes with side effects accept a token via
107`Authorization: Bearer <token>` or `X-API-Key: <token>`. When the variable is
108unset the routes stay open and a warning is logged at startup.
109 
110| Variable | Guards |
111| ------------------------- | ------------------------------------------------------------------------ |
112| `SCANNER_API_TOKEN` | `/scanner/scan`, `/scanner/reports/:id/export`, `/tools/scanner` |
113| `README_BADGES_API_TOKEN` | `/readme-badges/update`, `/readme-badges/detect`, `/tools/readme-badges` |
114 
115**Path containment.** `readme-badges` resolves `readmePath` and `rootDir`
116against `README_BADGES_ROOT` (default: the working directory) and refuses
117anything that escapes it, targets a non-markdown file, or reaches outside via a
118symlink. `scanner` confines exports to its reports directory the same way.
119 
120**Outbound request allowlists.** Modules that fetch caller-named URLs reject
121loopback, link-local (cloud metadata), RFC1918, CGNAT and other non-public
122addresses, resolve hostnames and check every returned address, and re-validate
123each redirect hop. Where a module talks to one known service, the host is also
124allowlisted:
125 
126| Variable | Extends the allowlist for |
127| --------------------------- | ---------------------------------------------------- |
128| `CONVERT2DOC_ALLOWED_HOSTS` | `convert2doc` `baseUrl` (default: `convert2doc.com`) |
129| `CRAIGSLIST_ALLOWED_HOSTS` | `/craigslist/details` (default: `*.craigslist.org`) |
130 
131**Cross-origin requests.** `CSRF_PROTECTION_ENABLED` (default `true`) rejects
132state-changing requests that carry a foreign `Origin` header, so a malicious web
133page cannot drive a browser at a localhost-bound server. Clients that send no
134`Origin` — curl, MCP clients, server-to-server calls — are unaffected. List
135trusted browser origins in `CORS_ORIGINS`.
136 
137Run the server behind an authenticating reverse proxy if it is exposed beyond
138localhost.
139 
140### Testing the Server
141 
142The repository includes comprehensive testing using Mocha and Chai:
143 
144```bash
145# Run all tests
146pnpm test
147 
148# Run only module tests
149pnpm test:modules
150 
151# Run all tests (both core and modules)
152pnpm test:all
153```
154 
155The testing infrastructure includes:
156 
1571. Core server tests for module loading, routing, and other core functionality
1582. Module-specific tests for each module's functionality
1593. Support for ES modules in tests
1604. Mocking and stubbing utilities with Sinon
161 
162Tests are organized in a structured way:
163 
164- Core tests in `/test/core/`
165- Module tests in each module's `test/` directory
166 
167This comprehensive testing ensures code quality and makes it easier to detect regressions when making changes.
168 
169### Pre-commit Hooks
170 
171The repository includes pre-commit hooks using Husky and lint-staged:
172 
173```bash
174# The hooks are automatically installed when you run
175pnpm install
176```
177 
178The pre-commit hooks:
179 
1801. Run ESLint on JavaScript files
1812. Run Prettier on all staged files
182 
183This ensures that all code committed to the repository follows coding standards and maintains code quality. The test suite is continuously being improved to provide better coverage and reliability, and will be enabled in the pre-commit hook once it's more stable.
184 
185### Docker Support
186 
187The repository includes Docker support for easy containerization and deployment:
188 
189```bash
190# Build and run with Docker
191docker build -t mcp-server .
192docker run -p 3000:3000 mcp-server
193 
194# Or use Docker Compose
195docker-compose up
196```
197 
198The Docker configuration:
199 
200- Uses Node.js 20 Alpine as the base image
201- Exposes port 3000
202- Mounts the modules directory as a volume for easy module management
203- Includes health checks
204 
205## Standard MCP Methods
206 
207The MCP server implements a standardized set of methods that all MCP servers should provide:
208 
209### Server Information
210 
211- `GET /` - Basic server information
212- `GET /status` - Detailed server status
213- `GET /health` - Health check endpoint
214- `GET /metrics` - Server metrics
215 
216### Model Management
217 
218- `GET /models` - List available models
219- `GET /model/:modelId` - Get model information
220- `POST /model/:modelId/activate` - Activate a specific model
221- `POST /model/deactivate` - Deactivate the current model
222- `GET /model/active` - Get information about the active model
223 
224### Inference
225 
226- `POST /model/infer` - Perform inference with the active model
227- `POST /model/:modelId/infer` - Perform inference with a specific model
228 
229#### Supported Models
230 
231The MCP server supports the following model types:
232 
233| Model Type | Provider | Capabilities | Example IDs |
234| ---------------- | ------------ | ---------------- | ------------------------------ |
235| GPT Models | OpenAI | Text generation | gpt-4, gpt-3.5-turbo |
236| Whisper | OpenAI | Speech-to-text | whisper, whisper-1 |
237| Stable Diffusion | Stability AI | Image generation | stable-diffusion-xl-1024-v1-0 |
238| Claude Models | Anthropic | Text generation | claude-3-opus, claude-3-sonnet |
239| Custom Models | Hugging Face | Various | (any Hugging Face model ID) |
240 
241#### Inference Examples
242 
243Text generation with GPT-4:
244 
245```bash
246# Activate the model
247curl -X POST http://localhost:3000/model/gpt-4/activate \
248 -H "Content-Type: application/json" \
249 -d '{"config": {"temperature": 0.7}}'
250 
251# Perform inference
252curl -X POST http://localhost:3000/model/infer \
253 -H "Content-Type: application/json" \
254 -d '{
255 "prompt": "Explain quantum computing in simple terms",
256 "temperature": 0.5,
257 "max_tokens": 200
258 }'
259```
260 
261Image generation with Stable Diffusion:
262 
263```bash
264# Activate the model
265curl -X POST http://localhost:3000/model/stable-diffusion/activate \
266 -H "Content-Type: application/json" \
267 -d '{}'
268 
269# Generate an image
270curl -X POST http://localhost:3000/model/infer \
271 -H "Content-Type: application/json" \
272 -d '{
273 "prompt": "A beautiful sunset over mountains",
274 "height": 1024,
275 "width": 1024,
276 "steps": 30
277 }'
278```
279 
280Streaming text generation:
281 
282```bash
283# Enable streaming
284curl -X POST http://localhost:3000/model/infer \
285 -H "Content-Type: application/json" \
286 -d '{
287 "prompt": "Write a short story about a robot",
288 "stream": true
289 }'
290```
291 
292### Module Management
293 
294- `GET /modules` - List installed modules
295- `GET /modules/:moduleId` - Get module information
296- `GET /modules/search/:query` - Search modules by any field in their package.json or metadata
297 
298### Tools and Resources
299 
300- `GET /tools` - List available tools
301- `GET /resources` - List available resources
302 
303For detailed information about these methods, see [MCP Standard Methods](docs/mcp_standard_methods.md).
304 
305## Configuration
306 
307Configuration is loaded from environment variables and stored in `src/core/config.js`. The easiest way to configure the server is to edit the `.env` file in the project root.
308 
309### Environment Variables
310 
311Key environment variables include:
312 
313| Variable | Description | Default |
314| ------------------- | ------------------------------------ | ---------------------------------- |
315| PORT | Server port | 3000 |
316| HOST | Server host | localhost |
317| NODE_ENV | Environment (development/production) | development |
318| OPENAI_API_KEY | OpenAI API key | (required for OpenAI models) |
319| STABILITY_API_KEY | Stability AI API key | (required for Stable Diffusion) |
320| ANTHROPIC_API_KEY | Anthropic API key | (required for Claude models) |
321| HUGGINGFACE_API_KEY | Hugging Face API key | (required for Hugging Face models) |
322 
323See `sample.env` for a complete list of configuration options.
324 
325## Examples
326 
327The repository includes several examples to help you get started:
328 
329- **Client Example**: `examples/client.js` demonstrates how to interact with the MCP server from a client application.
330- **Custom Module Example**: `examples/custom-module/` shows how to create a custom module that adds a calculator tool to the server.
331 
332To run the client example:
333 
334```bash
335node examples/client.js
336```
337 
338To use the custom module example, copy it to the modules directory:
339 
340```bash
341cp -r examples/custom-module mcp_modules/calculator
342```
343 
344## Creating Modules
345 
346Modules are the primary way to extend the MCP server. Each module is a self-contained package that can add new functionality to the server.
347 
348### Module Structure
349 
350Modules now follow an enhanced structure with better organization:
351 
352```
353mcp_modules/your-module/
354├── assets/ # Static assets (images, CSS, etc.)
355├── docs/ # Documentation files
356├── examples/ # Example usage
357├── src/ # Source code
358│ ├── controller.js # HTTP route handlers
359│ ├── service.js # Business logic
360│ └── utils.js # Utility functions
361├── test/ # Test files
362│ ├── controller.test.js
363│ └── service.test.js
364├── index.js # Main module file with register function
365├── package.json # Module metadata, dependencies, and scripts
366└── README.md # Module documentation
367```
368 
369Each module should include a `package.json` file with:
370 
371- Name, version, description
372- Author and license information
373- Dependencies and dev dependencies
374- Scripts (especially for testing)
375- Keywords and other metadata
376 
377This structure provides better separation of concerns, makes testing easier, and improves module discoverability.
378 
379### Module Implementation
380 
381The main module file (`index.js`) must export a `register` function that will be called when the module is loaded:
382 
383```javascript
384/**
385 * Register this module with the Hono app
386 * @param {import('hono').Hono} app - The Hono app instance
387 */
388export async function register(app) {
389 // Register routes, middleware, etc.
390 app.get('/your-module/endpoint', c => {
391 return c.json({ message: 'Your module is working!' });
392 });
393}
394 
395// Optional: Export module metadata
396export const metadata = {
397 name: 'Your Module',
398 version: '1.0.0',
399 description: 'Description of your module',
400 author: 'Your Name',
401};
402```
403 
404### Example Modules
405 
406- A simple example module is provided in `mcp_modules/example/` to demonstrate how to create a module.
407- A more complex example with a calculator tool is provided in `examples/custom-module/`.
408- A health check module is provided in `mcp_modules/health-check/` for system monitoring.
409- A template for creating new modules is available in `mcp_modules/template/`.
410 
411### Creating New Modules
412 
413You can create a new module using the provided script:
414 
415```bash
416# Create a new module
417pnpm create-module
418 
419# Or with a module name
420pnpm create-module my-module
421```
422 
423The script will:
424 
4251. Create a new module directory in `mcp_modules/`
4262. Copy the template files
4273. Replace placeholders with your module information
4284. Provide next steps for implementing your module
429 
430## Module Search
431 
432The MCP server includes a powerful search functionality that allows you to find modules based on any information in their package.json or metadata.
433 
434### Search Endpoints
435 
436- `GET /modules/search/:query` - Search for modules containing the specified query string in any field
437 
438### Search Examples
439 
440```bash
441# Find modules by name or description
442curl http://localhost:3000/modules/search/craigslist
443 
444# Find modules by dependency
445curl http://localhost:3000/modules/search/jsdom
446 
447# Find modules by keyword
448curl http://localhost:3000/modules/search/mcp
449 
450# Find modules by author
451curl http://localhost:3000/modules/search/"MCP Server Team"
452 
453# Find modules by license
454curl http://localhost:3000/modules/search/ISC
455```
456 
457### JavaScript Example
458 
459```javascript
460// Function to search modules by any field
461async function searchModules(query) {
462 const response = await fetch(`http://localhost:3000/modules/search/${query}`);
463 const data = await response.json();
464 
465 console.log(`Found ${data.count} modules matching "${query}":`);
466 data.results.forEach(module => {
467 console.log(`- ${module.name} (${module.directoryName}): ${module.description}`);
468 });
469 
470 return data.results;
471}
472```
473 
474The search is comprehensive and will find matches in any field, including nested objects like dependencies, keywords, and other metadata.
475 
476## Model Providers
477 
478The MCP server integrates with several AI model providers:
479 
480### OpenAI
481 
482OpenAI provides GPT models for text generation and Whisper for speech-to-text:
483 
484```javascript
485// Text generation example
486const response = await fetch('http://localhost:3000/model/infer', {
487 method: 'POST',
488 headers: { 'Content-Type': 'application/json' },
489 body: JSON.stringify({
490 prompt: 'Write a poem about artificial intelligence',
491 temperature: 0.7,
492 max_tokens: 200,
493 }),
494});
495 
496// Speech-to-text example (requires multipart form data)
497const formData = new FormData();
498formData.append('file', audioFile);
499formData.append('model', 'whisper-1');
500formData.append('language', 'en');
501 
502const response = await fetch('http://localhost:3000/model/whisper/infer', {
503 method: 'POST',
504 body: formData,
505});
506```
507 
508### Stability AI
509 
510Stability AI provides Stable Diffusion for image generation:
511 
512```javascript
513const response = await fetch('http://localhost:3000/model/infer', {
514 method: 'POST',
515 headers: { 'Content-Type': 'application/json' },
516 body: JSON.stringify({
517 prompt: 'A photorealistic image of a futuristic city',
518 height: 1024,
519 width: 1024,
520 steps: 30,
521 cfg_scale: 7,
522 }),
523});
524 
525// The response includes base64-encoded images
526const result = await response.json();
527const imageBase64 = result.response[0].base64;
528```
529 
530### Anthropic
531 
532Anthropic provides Claude models for text generation:
533 
534```javascript
535const response = await fetch('http://localhost:3000/model/infer', {
536 method: 'POST',
537 headers: { 'Content-Type': 'application/json' },
538 body: JSON.stringify({
539 prompt: 'Explain how neural networks work',
540 temperature: 0.5,
541 max_tokens: 300,
542 }),
543});
544```
545 
546### Hugging Face
547 
548Hugging Face provides access to thousands of open-source models:
549 
550```javascript
551const response = await fetch('http://localhost:3000/model/custom-model-name/infer', {
552 method: 'POST',
553 headers: { 'Content-Type': 'application/json' },
554 body: JSON.stringify({
555 prompt: 'Input for the model',
556 parameters: {
557 // Model-specific parameters
558 },
559 }),
560});
561```
562 
563## Documentation
564 
565- [MCP Standard Methods](docs/mcp_standard_methods.md): Documentation of the standard methods that all MCP servers should implement.
566- [MCP Interface](docs/mcp_interface.ts): TypeScript interface definitions for the MCP protocol.
567- [Architecture](docs/architecture.md): Overview of the MCP server architecture.
568 
569<a href="https://glama.ai/mcp/servers/@profullstack/mcp-server">
570 <img width="380" height="200" src="https://glama.ai/mcp/servers/@profullstack/mcp-server/badge" />
571 
572## License
573 
574ISC
575 

Discussion

Alternatives