@elsium-ai/mcp 0.2.1 → 0.2.2
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 +235 -12
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @elsium-ai/mcp
|
|
2
2
|
|
|
3
|
-
Model Context Protocol (MCP) support for [ElsiumAI](https://github.com/elsium-ai/elsium-ai)
|
|
3
|
+
Model Context Protocol (MCP) support for [ElsiumAI](https://github.com/elsium-ai/elsium-ai) -- bidirectional client and server over stdio transport.
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/@elsium-ai/mcp)
|
|
6
6
|
[](https://github.com/elsium-ai/elsium-ai/blob/main/LICENSE)
|
|
@@ -8,31 +8,254 @@ Model Context Protocol (MCP) support for [ElsiumAI](https://github.com/elsium-ai
|
|
|
8
8
|
## Install
|
|
9
9
|
|
|
10
10
|
```bash
|
|
11
|
-
npm install @elsium-ai/mcp
|
|
11
|
+
npm install @elsium-ai/mcp
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Peer dependencies `@elsium-ai/core` and `@elsium-ai/tools` are pulled in automatically when you install within the ElsiumAI monorepo. In standalone usage, install them explicitly:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @elsium-ai/mcp @elsium-ai/core @elsium-ai/tools
|
|
12
18
|
```
|
|
13
19
|
|
|
14
20
|
## What's Inside
|
|
15
21
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
22
|
+
| Category | Export | Kind | Description |
|
|
23
|
+
| -------- | ------ | ---- | ----------- |
|
|
24
|
+
| **Client** | `createMCPClient` | function | Create an MCP client that connects to an external MCP server over stdio |
|
|
25
|
+
| | `MCPClient` | interface | Shape of the object returned by `createMCPClient` |
|
|
26
|
+
| | `MCPClientConfig` | interface | Configuration for `createMCPClient` |
|
|
27
|
+
| | `MCPToolInfo` | interface | Metadata for a single tool reported by an MCP server |
|
|
28
|
+
| **Server** | `createMCPServer` | function | Create an MCP server that exposes ElsiumAI tools over stdio |
|
|
29
|
+
| | `MCPServer` | interface | Shape of the object returned by `createMCPServer` |
|
|
30
|
+
| | `MCPServerConfig` | interface | Configuration for `createMCPServer` |
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## Client
|
|
35
|
+
|
|
36
|
+
### `MCPClientConfig`
|
|
37
|
+
|
|
38
|
+
Configuration object passed to `createMCPClient`.
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
interface MCPClientConfig {
|
|
42
|
+
name: string
|
|
43
|
+
transport: 'stdio'
|
|
44
|
+
command: string
|
|
45
|
+
args?: string[]
|
|
46
|
+
env?: Record<string, string>
|
|
47
|
+
timeoutMs?: number
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
| Property | Type | Required | Default | Description |
|
|
52
|
+
| -------- | ---- | -------- | ------- | ----------- |
|
|
53
|
+
| `name` | `string` | yes | -- | Logical name for this client connection (used in the protocol handshake) |
|
|
54
|
+
| `transport` | `'stdio'` | yes | -- | Transport type. Currently only `'stdio'` is supported |
|
|
55
|
+
| `command` | `string` | yes | -- | The command to spawn the MCP server subprocess (e.g. `"npx"`, `"node"`) |
|
|
56
|
+
| `args` | `string[]` | no | `[]` | Arguments passed to the spawned command |
|
|
57
|
+
| `env` | `Record<string, string>` | no | `{}` | Additional environment variables for the subprocess. `PATH` and `HOME` are inherited automatically |
|
|
58
|
+
| `timeoutMs` | `number` | no | `30000` | Timeout in milliseconds for each JSON-RPC request |
|
|
59
|
+
|
|
60
|
+
### `MCPToolInfo`
|
|
61
|
+
|
|
62
|
+
Describes a single tool as reported by an MCP server's `tools/list` response.
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
interface MCPToolInfo {
|
|
66
|
+
name: string
|
|
67
|
+
description: string
|
|
68
|
+
inputSchema: Record<string, unknown>
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### `MCPClient`
|
|
73
|
+
|
|
74
|
+
The interface returned by `createMCPClient`. Provides methods for connecting to an MCP server, discovering its tools, calling them, and converting them into ElsiumAI-compatible `Tool` objects.
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
interface MCPClient {
|
|
78
|
+
connect(): Promise<void>
|
|
79
|
+
disconnect(): Promise<void>
|
|
80
|
+
listTools(): Promise<MCPToolInfo[]>
|
|
81
|
+
callTool(name: string, args: Record<string, unknown>): Promise<unknown>
|
|
82
|
+
toElsiumTools(): Promise<Tool[]>
|
|
83
|
+
readonly connected: boolean
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
| Member | Description |
|
|
88
|
+
| ------ | ----------- |
|
|
89
|
+
| `connected` | Read-only boolean indicating whether the client is currently connected |
|
|
90
|
+
| `connect()` | Spawn the subprocess, perform the MCP `initialize` handshake, and send the `notifications/initialized` notification |
|
|
91
|
+
| `disconnect()` | Terminate the subprocess, reject all pending requests, and clean up |
|
|
92
|
+
| `listTools()` | Send a `tools/list` request and return the available tools |
|
|
93
|
+
| `callTool(name, args)` | Invoke a tool on the remote server. Returns the concatenated text content from the response |
|
|
94
|
+
| `toElsiumTools()` | List all remote tools and wrap each one as an ElsiumAI `Tool`, ready to be passed to an agent |
|
|
95
|
+
|
|
96
|
+
### `createMCPClient(config)`
|
|
19
97
|
|
|
20
|
-
|
|
98
|
+
Create a new MCP client. The client does not connect automatically -- call `connect()` before using it.
|
|
21
99
|
|
|
22
100
|
```typescript
|
|
23
|
-
|
|
101
|
+
function createMCPClient(config: MCPClientConfig): MCPClient
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
**Parameters**
|
|
105
|
+
|
|
106
|
+
| Name | Type | Description |
|
|
107
|
+
| ---- | ---- | ----------- |
|
|
108
|
+
| `config` | `MCPClientConfig` | Client configuration (see above) |
|
|
109
|
+
|
|
110
|
+
**Returns** -- `MCPClient`
|
|
111
|
+
|
|
112
|
+
**Example -- connect to an MCP server and list its tools**
|
|
113
|
+
|
|
114
|
+
```typescript
|
|
115
|
+
import { createMCPClient } from '@elsium-ai/mcp'
|
|
116
|
+
|
|
117
|
+
const client = createMCPClient({
|
|
118
|
+
name: 'filesystem',
|
|
119
|
+
transport: 'stdio',
|
|
120
|
+
command: 'npx',
|
|
121
|
+
args: ['-y', '@modelcontextprotocol/server-filesystem', '/tmp'],
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
await client.connect()
|
|
24
125
|
|
|
25
|
-
// Client — connect to an MCP server
|
|
26
|
-
const client = createMCPClient({ url: 'http://localhost:3001/mcp' })
|
|
27
126
|
const tools = await client.listTools()
|
|
127
|
+
console.log(tools)
|
|
128
|
+
// [{ name: 'read_file', description: '...', inputSchema: { ... } }, ...]
|
|
129
|
+
|
|
130
|
+
await client.disconnect()
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
**Example -- call a remote tool directly**
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
import { createMCPClient } from '@elsium-ai/mcp'
|
|
137
|
+
|
|
138
|
+
const client = createMCPClient({
|
|
139
|
+
name: 'filesystem',
|
|
140
|
+
transport: 'stdio',
|
|
141
|
+
command: 'npx',
|
|
142
|
+
args: ['-y', '@modelcontextprotocol/server-filesystem', '/tmp'],
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
await client.connect()
|
|
146
|
+
|
|
147
|
+
const content = await client.callTool('read_file', { path: '/tmp/hello.txt' })
|
|
148
|
+
console.log(content) // file contents as a string
|
|
149
|
+
|
|
150
|
+
await client.disconnect()
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
**Example -- convert MCP tools into ElsiumAI tools for an agent**
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
import { createMCPClient } from '@elsium-ai/mcp'
|
|
157
|
+
|
|
158
|
+
const client = createMCPClient({
|
|
159
|
+
name: 'filesystem',
|
|
160
|
+
transport: 'stdio',
|
|
161
|
+
command: 'npx',
|
|
162
|
+
args: ['-y', '@modelcontextprotocol/server-filesystem', '/tmp'],
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
await client.connect()
|
|
166
|
+
|
|
167
|
+
// Each returned Tool has execute() and toDefinition() wired through the MCP client
|
|
168
|
+
const elsiumTools = await client.toElsiumTools()
|
|
169
|
+
|
|
170
|
+
// Pass them to an agent, a toolkit, or call execute() directly
|
|
171
|
+
const result = await elsiumTools[0].execute({ path: '/tmp/hello.txt' })
|
|
172
|
+
console.log(result)
|
|
173
|
+
// { success: true, data: '...', toolCallId: 'tc_...', durationMs: 42 }
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
---
|
|
177
|
+
|
|
178
|
+
## Server
|
|
179
|
+
|
|
180
|
+
### `MCPServerConfig`
|
|
181
|
+
|
|
182
|
+
Configuration object passed to `createMCPServer`.
|
|
183
|
+
|
|
184
|
+
```typescript
|
|
185
|
+
interface MCPServerConfig {
|
|
186
|
+
name: string
|
|
187
|
+
version?: string
|
|
188
|
+
tools: Tool[]
|
|
189
|
+
}
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
| Property | Type | Required | Default | Description |
|
|
193
|
+
| -------- | ---- | -------- | ------- | ----------- |
|
|
194
|
+
| `name` | `string` | yes | -- | Server name reported in the `initialize` handshake |
|
|
195
|
+
| `version` | `string` | no | `'0.1.0'` | Server version reported in the `initialize` handshake |
|
|
196
|
+
| `tools` | `Tool[]` | yes | -- | Array of ElsiumAI `Tool` objects to expose over MCP |
|
|
197
|
+
|
|
198
|
+
### `MCPServer`
|
|
199
|
+
|
|
200
|
+
The interface returned by `createMCPServer`. The server reads JSON-RPC requests from `stdin` and writes responses to `stdout`, implementing the MCP protocol over stdio transport.
|
|
201
|
+
|
|
202
|
+
```typescript
|
|
203
|
+
interface MCPServer {
|
|
204
|
+
start(): Promise<void>
|
|
205
|
+
stop(): void
|
|
206
|
+
readonly running: boolean
|
|
207
|
+
}
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
| Member | Description |
|
|
211
|
+
| ------ | ----------- |
|
|
212
|
+
| `running` | Read-only boolean indicating whether the server is currently listening for requests |
|
|
213
|
+
| `start()` | Begin listening on `stdin` for incoming JSON-RPC messages. Handles `initialize`, `notifications/initialized`, `tools/list`, and `tools/call` |
|
|
214
|
+
| `stop()` | Stop the server by setting the running flag to false |
|
|
215
|
+
|
|
216
|
+
### `createMCPServer(config)`
|
|
217
|
+
|
|
218
|
+
Create a new MCP server that exposes the provided ElsiumAI tools over the MCP protocol.
|
|
219
|
+
|
|
220
|
+
```typescript
|
|
221
|
+
function createMCPServer(config: MCPServerConfig): MCPServer
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
**Parameters**
|
|
225
|
+
|
|
226
|
+
| Name | Type | Description |
|
|
227
|
+
| ---- | ---- | ----------- |
|
|
228
|
+
| `config` | `MCPServerConfig` | Server configuration (see above) |
|
|
229
|
+
|
|
230
|
+
**Returns** -- `MCPServer`
|
|
231
|
+
|
|
232
|
+
**Example -- expose ElsiumAI tools as an MCP server**
|
|
233
|
+
|
|
234
|
+
```typescript
|
|
235
|
+
import { createMCPServer } from '@elsium-ai/mcp'
|
|
236
|
+
import { createTool } from '@elsium-ai/tools'
|
|
237
|
+
import { z } from 'zod'
|
|
238
|
+
|
|
239
|
+
const greet = createTool({
|
|
240
|
+
name: 'greet',
|
|
241
|
+
description: 'Return a greeting for the given name',
|
|
242
|
+
input: z.object({ name: z.string() }),
|
|
243
|
+
execute: async ({ input }) => `Hello, ${input.name}!`,
|
|
244
|
+
})
|
|
28
245
|
|
|
29
|
-
// Server — expose tools via MCP
|
|
30
246
|
const server = createMCPServer({
|
|
31
|
-
|
|
32
|
-
|
|
247
|
+
name: 'my-tools',
|
|
248
|
+
version: '1.0.0',
|
|
249
|
+
tools: [greet],
|
|
33
250
|
})
|
|
251
|
+
|
|
252
|
+
await server.start()
|
|
253
|
+
// The server is now listening on stdin/stdout.
|
|
254
|
+
// MCP clients (e.g. Claude Desktop) can connect to it via stdio transport.
|
|
34
255
|
```
|
|
35
256
|
|
|
257
|
+
---
|
|
258
|
+
|
|
36
259
|
## Part of ElsiumAI
|
|
37
260
|
|
|
38
261
|
This package is the MCP layer of the [ElsiumAI](https://github.com/elsium-ai/elsium-ai) framework. See the [full documentation](https://github.com/elsium-ai/elsium-ai) for guides and examples.
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elsium-ai/mcp",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Model Context Protocol (MCP) support for ElsiumAI — bidirectional bridge",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Eric Utrera <ebutrera9103@gmail.com>",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
|
-
"url": "https://github.com/elsium-ai/elsium-ai",
|
|
9
|
+
"url": "git+https://github.com/elsium-ai/elsium-ai.git",
|
|
10
10
|
"directory": "packages/mcp"
|
|
11
11
|
},
|
|
12
12
|
"type": "module",
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
"dev": "bun --watch src/index.ts"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@elsium-ai/core": "^0.2.
|
|
30
|
-
"@elsium-ai/tools": "^0.2.
|
|
29
|
+
"@elsium-ai/core": "^0.2.2",
|
|
30
|
+
"@elsium-ai/tools": "^0.2.2"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"typescript": "^5.7.0"
|