Skip to content

Commit 95b922c

Browse files
authored
Merge pull request #35 from piyook/feat/mcp-integration
Feat(): add mcp integration
2 parents a642e8c + 71a91e1 commit 95b922c

23 files changed

+8316
-7021
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
node_modules
22
*.log
3-
screenshots/
4-
videos/
3+
cypress/screenshots/
4+
cypress/videos/

README.md

Lines changed: 78 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
![Github actions](https://github.com/piyook/mock-api-framework-template/actions/workflows/tests.yaml/badge.svg)
33
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
44

5-
# Local Mock API Framework
5+
# Local Mock API Framework and MCP Server
66

77
## Purpose
88

@@ -25,6 +25,8 @@ The framework is written in TypeScript and can :
2525
- Mock API error codes/messages for testing frontend error handling logic
2626
- Log and store API requests in JSON format and display information on the localhost:8000/logs route
2727

28+
The project has a local MCP server (experimental) to connect to LLM Agents (such as Claude Desktop, Cursor etc.,) that use the MCP protocol. This allows the Local Mock API server to be managed using an LLM for easier interactions during development.
29+
2830
## Set-up
2931

3032
#### Requirements
@@ -63,7 +65,7 @@ A list of all endpoints can be viewed on http://localhost:8000/.
6365

6466
The project has been set-up with demo endpoints that can be removed or modified as needed.
6567

66-
![main server page](image.png)
68+
![main server page](images/image.png)
6769

6870
### Useful Commands
6971

@@ -311,7 +313,7 @@ API request information and sent data can be logged and stored as JSON in the /s
311313

312314
Logs can be viewed at **localhost:8000/logs**.
313315

314-
![logging](logs.png)
316+
![logging](images/logs.png)
315317

316318
### Set-up
317319

@@ -371,3 +373,76 @@ By default this is set to 8000 but can be changed by setting the SERVER_PORT in
371373
```js
372374
SERVER_PORT = 1234;
373375
```
376+
377+
# MCP Server (Experimental)
378+
379+
### Set-up
380+
381+
Connect the mcp server to the mock api server as described in your agents documentation. Note the MCP server.js file is in the src/mcp folder.
382+
383+
You can run the command below to build the mcp server.js file if needed.
384+
385+
```bash
386+
npm run mcp:build
387+
```
388+
389+
then use the path below to connect to the mcp server in the MCP config file
390+
391+
```bash
392+
<path_to_the_local_project_folder>/src/mcp/server.js
393+
```
394+
395+
### Usage
396+
397+
You can request the LLM agent to start, stop and rebuild the LOCAL MOCK API server and to check for available api endpoints using the manage_local_mock_api_server tool.
398+
399+
You can also request the agent build a new api endpoint using the create_new_api_endpoint tool.
400+
401+
Note: the mcp server will only work with a local mock api server <b>running in a Docker container.</b>
402+
403+
![mcp-1](images/mcp-1.png)
404+
405+
![mcp-2](images/mcp-2.png)
406+
407+
### Issues
408+
409+
#### Node version managers
410+
411+
If using a node version manager such as NVM or FNM in Windows, then you may need to either specify the entire path to the node binary in the mcp server config file or set the system NODE_PATH environment variable to direct the path of the fnm aliases directory (or create sym links in linux / mac) - see https://github.com/modelcontextprotocol/servers/issues/40#issuecomment-2588950176 or https://github.com/Schniz/fnm/issues/1366#issuecomment-2764510266
412+
413+
E.g with fnm aliases in PATH the config below works with fnm and node
414+
415+
```bash
416+
"mcpServers": {
417+
"LocalMockAPIServer": {
418+
"command": "node",
419+
"args": [
420+
"<path-to-your-project>\\mock-api-framework-template\\src\\mcp\\server.js"
421+
]
422+
...
423+
424+
```
425+
426+
#### Custom Port Numbers
427+
428+
If changing the PORT number from 8000 in the env of the Mock Server then manually update the mcp/server.ts file PORT variable to the match the updated port number and run
429+
430+
```bash
431+
npm run mcp:build
432+
```
433+
434+
then restart your mcp agents to update the connection.
435+
436+
### Debugging/Testing the MCP server
437+
438+
You can test the mcp server using the mcp inspector tool (@modelcontextprotocol/inspector) by running
439+
440+
```bash
441+
npm run mcp:debug
442+
```
443+
444+
This will open a browser window and connect to the mcp server to manually run tools for testing.
445+
446+
### New Issues
447+
448+
Note: The MCP Server feature is currently experimental - log any issues here https://github.com/piyook/mock-api-framework-template/issues.
File renamed without changes.
File renamed without changes.

images/mcp-1.png

67.3 KB
Loading

images/mcp-2.png

110 KB
Loading

0 commit comments

Comments
 (0)