iflow-mcp-hemanth-hello-remote 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +113 -0
- package/dist/index.js +8 -0
- package/dist/prompts/GreetPrompt.js +25 -0
- package/dist/resources/DynamicResource.js +17 -0
- package/dist/resources/RealTimeResource.js +33 -0
- package/dist/resources/StaticResource.js +17 -0
- package/dist/tools/XkcdTool.js +41 -0
- package/package.json +1 -0
package/README.md
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# mcp-remote-server
|
|
2
|
+
|
|
3
|
+
A Model Context Protocol (MCP) server built with mcp-framework.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# Install dependencies
|
|
9
|
+
npm install
|
|
10
|
+
|
|
11
|
+
# Build the project
|
|
12
|
+
npm run build
|
|
13
|
+
|
|
14
|
+
# Start the server
|
|
15
|
+
npm start
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
The server will run on port **1947** at endpoint **/mcp** by default.
|
|
19
|
+
|
|
20
|
+
## Project Structure
|
|
21
|
+
|
|
22
|
+
```
|
|
23
|
+
mcp-remote-server/
|
|
24
|
+
├── src/
|
|
25
|
+
│ ├── tools/ # MCP Tools
|
|
26
|
+
│ │ └── XkcdTool.ts # Tool: Fetches random xkcd comics
|
|
27
|
+
│ ├── resources/ # MCP Resources
|
|
28
|
+
│ │ ├── DynamicResource.ts # Fetches data from JSONPlaceholder
|
|
29
|
+
│ │ ├── RealTimeResource.ts # Echo WebSocket resource
|
|
30
|
+
│ │ └── StaticResource.ts # Returns static JSON data
|
|
31
|
+
│ └── index.ts # Server entry point
|
|
32
|
+
├── package.json
|
|
33
|
+
├── tsconfig.json
|
|
34
|
+
└── README.md
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Included Tools
|
|
38
|
+
|
|
39
|
+
### XkcdTool
|
|
40
|
+
- **Name:** `xkcd`
|
|
41
|
+
- **Description:** Fetches a random xkcd comic image and its alt text.
|
|
42
|
+
|
|
43
|
+
## Included Resources
|
|
44
|
+
|
|
45
|
+
### DynamicResource
|
|
46
|
+
- **URI:** `resource://market-data`
|
|
47
|
+
- **Description:** Fetches data from [JSONPlaceholder](https://jsonplaceholder.typicode.com/posts) (free, no API key required).
|
|
48
|
+
|
|
49
|
+
### EchoResource
|
|
50
|
+
- **URI:** `resource://echo`
|
|
51
|
+
- **Description:** Connects to a public WebSocket echo server (`wss://echo.websocket.org`).
|
|
52
|
+
|
|
53
|
+
### StaticResource
|
|
54
|
+
- **URI:** `resource://static`
|
|
55
|
+
- **Description:** Returns static JSON data for testing.
|
|
56
|
+
|
|
57
|
+
## Adding Components
|
|
58
|
+
|
|
59
|
+
You can add more tools using the CLI:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
# Add a new tool
|
|
63
|
+
mcp add tool my-tool
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Tool Development Example
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
import { MCPTool } from "mcp-framework";
|
|
70
|
+
import { z } from "zod";
|
|
71
|
+
|
|
72
|
+
interface MyToolInput {
|
|
73
|
+
message: string;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
class MyTool extends MCPTool<MyToolInput> {
|
|
77
|
+
name = "my_tool";
|
|
78
|
+
description = "Describes what your tool does";
|
|
79
|
+
|
|
80
|
+
schema = {
|
|
81
|
+
message: {
|
|
82
|
+
type: z.string(),
|
|
83
|
+
description: "Description of this input parameter",
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
async execute(input: MyToolInput) {
|
|
88
|
+
// Your tool logic here
|
|
89
|
+
return `Processed: ${input.message}`;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export default MyTool;
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Running and Testing
|
|
97
|
+
|
|
98
|
+
1. Make changes to your tools or resources as needed.
|
|
99
|
+
2. Run `npm run build` to compile.
|
|
100
|
+
3. Start the server with `npm start`.
|
|
101
|
+
4. The server will automatically load your tools and resources on startup.
|
|
102
|
+
|
|
103
|
+
## Server Details
|
|
104
|
+
- **Port:** 1947
|
|
105
|
+
- **Endpoint:** `/mcp`
|
|
106
|
+
- **Transport:** HTTP stream
|
|
107
|
+
- **Session management:** Enabled
|
|
108
|
+
- **CORS:** Enabled for all origins
|
|
109
|
+
|
|
110
|
+
## Learn More
|
|
111
|
+
|
|
112
|
+
- [MCP Framework Github](https://github.com/QuantGeekDev/mcp-framework)
|
|
113
|
+
- [MCP Framework Docs](https://mcp-framework.com)
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { MCPPrompt } from "mcp-framework";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
class GreetPrompt extends MCPPrompt {
|
|
4
|
+
name = "greet";
|
|
5
|
+
description = "Greet prompt description";
|
|
6
|
+
schema = {
|
|
7
|
+
message: z.object({
|
|
8
|
+
type: z.string(),
|
|
9
|
+
description: z.string(),
|
|
10
|
+
required: z.boolean(),
|
|
11
|
+
}),
|
|
12
|
+
};
|
|
13
|
+
async generateMessages({ message }) {
|
|
14
|
+
return [
|
|
15
|
+
{
|
|
16
|
+
role: "user",
|
|
17
|
+
content: {
|
|
18
|
+
type: "text",
|
|
19
|
+
text: `echo: ${message}`,
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export default GreetPrompt;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { MCPResource } from "mcp-framework";
|
|
2
|
+
class MarketDataResource extends MCPResource {
|
|
3
|
+
uri = "resource://market-data";
|
|
4
|
+
name = "Market Data";
|
|
5
|
+
mimeType = "application/json";
|
|
6
|
+
async read() {
|
|
7
|
+
const data = await this.fetch("https://jsonplaceholder.typicode.com/posts");
|
|
8
|
+
return [
|
|
9
|
+
{
|
|
10
|
+
uri: this.uri,
|
|
11
|
+
mimeType: this.mimeType,
|
|
12
|
+
text: JSON.stringify(data),
|
|
13
|
+
},
|
|
14
|
+
];
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export default MarketDataResource;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { MCPResource } from "mcp-framework";
|
|
2
|
+
class EchoResource extends MCPResource {
|
|
3
|
+
uri = "resource://echo";
|
|
4
|
+
name = "Echo";
|
|
5
|
+
mimeType = "application/json";
|
|
6
|
+
ws = null;
|
|
7
|
+
async subscribe() {
|
|
8
|
+
this.ws = new WebSocket("wss://echo.websocket.org");
|
|
9
|
+
this.ws.onmessage = (event) => {
|
|
10
|
+
console.log('Received:', event.data);
|
|
11
|
+
};
|
|
12
|
+
// Send a test message
|
|
13
|
+
this.ws.onopen = () => {
|
|
14
|
+
this.ws?.send('Hello WebSocket!');
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
async unsubscribe() {
|
|
18
|
+
if (this.ws) {
|
|
19
|
+
this.ws.close();
|
|
20
|
+
this.ws = null;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
async read() {
|
|
24
|
+
return [
|
|
25
|
+
{
|
|
26
|
+
uri: this.uri,
|
|
27
|
+
mimeType: this.mimeType,
|
|
28
|
+
text: 'Connected to WebSocket echo server'
|
|
29
|
+
},
|
|
30
|
+
];
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export default EchoResource;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { MCPResource } from "mcp-framework";
|
|
2
|
+
class StaticResource extends MCPResource {
|
|
3
|
+
uri = "resource://static";
|
|
4
|
+
name = "Static";
|
|
5
|
+
description = "Static resource description";
|
|
6
|
+
mimeType = "application/json";
|
|
7
|
+
async read() {
|
|
8
|
+
return [
|
|
9
|
+
{
|
|
10
|
+
uri: this.uri,
|
|
11
|
+
mimeType: this.mimeType,
|
|
12
|
+
text: JSON.stringify({ message: "Hello from Static resource" }),
|
|
13
|
+
},
|
|
14
|
+
];
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export default StaticResource;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { MCPTool } from "mcp-framework";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
class XkcdTool extends MCPTool {
|
|
4
|
+
name = "xkcd";
|
|
5
|
+
description = "Fetches a random xkcd comic image and its alt text.";
|
|
6
|
+
schema = {
|
|
7
|
+
message: {
|
|
8
|
+
type: z.string(),
|
|
9
|
+
description: "Message to process",
|
|
10
|
+
},
|
|
11
|
+
};
|
|
12
|
+
async execute() {
|
|
13
|
+
try {
|
|
14
|
+
// Get the latest comic number
|
|
15
|
+
const latestComicResponse = await fetch("https://xkcd.com/info.0.json");
|
|
16
|
+
if (!latestComicResponse.ok) {
|
|
17
|
+
throw new Error(`Failed to fetch latest comic data: ${latestComicResponse.statusText}`);
|
|
18
|
+
}
|
|
19
|
+
const latestComicData = (await latestComicResponse.json());
|
|
20
|
+
const latestComicNumber = latestComicData.num;
|
|
21
|
+
// Generate a random comic number
|
|
22
|
+
const randomComicNumber = Math.floor(Math.random() * latestComicNumber) + 1;
|
|
23
|
+
// Fetch the random comic
|
|
24
|
+
const randomComicResponse = await fetch(`https://xkcd.com/${randomComicNumber}/info.0.json`);
|
|
25
|
+
if (!randomComicResponse.ok) {
|
|
26
|
+
throw new Error(`Failed to fetch comic data for ${randomComicNumber}: ${randomComicResponse.statusText}`);
|
|
27
|
+
}
|
|
28
|
+
const randomComicData = (await randomComicResponse.json());
|
|
29
|
+
return `
|
|
30
|
+
Title: ${randomComicData.title}
|
|
31
|
+
Image URL: ${randomComicData.img}
|
|
32
|
+
Alt Text: ${randomComicData.alt}
|
|
33
|
+
`;
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
console.error("Error fetching xkcd comic:", error);
|
|
37
|
+
return "Error: Could not fetch xkcd comic.";
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export default XkcdTool;
|
package/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"name": "iflow-mcp-hemanth-hello-remote", "version": "0.0.1", "description": "mcp-remote-server MCP server", "type": "module", "bin": {"iflow-mcp-hemanth-hello-remote": "./dist/index.js"}, "files": ["dist"], "scripts": {"build": "tsc && mcp-build", "watch": "tsc --watch", "start": "node dist/index.js"}, "dependencies": {"mcp-framework": "^0.2.2"}, "devDependencies": {"@types/node": "^20.11.24", "typescript": "^5.3.3"}, "engines": {"node": ">=18.19.0"}}
|