@empyria/mcp 0.1.0 → 0.1.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/AGENTS.md +1 -1
- package/README.md +9 -9
- package/lib/Gateway.js +1 -1
- package/lib/Server.js +2 -5
- package/lib/Validator.js +2 -2
- package/package.json +4 -4
- package/test/Validator.test.js +5 -5
package/AGENTS.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# AGENTS.md
|
|
2
2
|
|
|
3
|
-
MCP (Model Context Protocol) helpers for **
|
|
3
|
+
MCP (Model Context Protocol) helpers for **Empyria**, a nanoservice framework built
|
|
4
4
|
primarily on Bun: publishes Moleculer-shaped `{ name, actions }` service objects as MCP tools.
|
|
5
5
|
|
|
6
6
|
## The package split that matters here
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @empyria/mcp
|
|
2
2
|
|
|
3
|
-
[MCP (Model Context Protocol)](https://modelcontextprotocol.io) helpers for **
|
|
3
|
+
[MCP (Model Context Protocol)](https://modelcontextprotocol.io) helpers for **Empyria**, a
|
|
4
4
|
nanoservice framework built primarily on Bun: publish a list of Moleculer-shaped services as
|
|
5
5
|
MCP tools, with JSON Schema input validation via `@empyria/common`'s `createValidator` —
|
|
6
6
|
no Zod, no Ajv, in our own code.
|
|
@@ -177,14 +177,14 @@ that same instance — including as `createMcpHandler`'s per-request factory for
|
|
|
177
177
|
|
|
178
178
|
## Modules
|
|
179
179
|
|
|
180
|
-
| Module | Purpose
|
|
181
|
-
| -------------------------------------- |
|
|
182
|
-
| [lib/Server.js](./lib/Server.js) | `createMcpServer` — publishes a list of Moleculer-shaped `{ name, actions }` services as MCP tools.
|
|
183
|
-
| [lib/Http.js](./lib/Http.js) | `createMcpHttpHandler` (runtime-agnostic Web-standard handler) and `serveMcpHttp` (Bun-only convenience, wraps `Bun.serve`).
|
|
184
|
-
| [lib/Guard.js](./lib/Guard.js) | `withMetaGuard` — optional per-service token protection; see above.
|
|
185
|
-
| [lib/Client.js](./lib/Client.js) | `createMcpClient`, `connectStdioClient`, `connectHttpClient` — client-side helpers.
|
|
186
|
-
| [lib/Gateway.js](./lib/Gateway.js) | `createMcpGateway` — aggregates several already-connected upstream MCP clients into one server.
|
|
187
|
-
| [lib/Validator.js](./lib/Validator.js) | `
|
|
180
|
+
| Module | Purpose |
|
|
181
|
+
| -------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
182
|
+
| [lib/Server.js](./lib/Server.js) | `createMcpServer` — publishes a list of Moleculer-shaped `{ name, actions }` services as MCP tools. |
|
|
183
|
+
| [lib/Http.js](./lib/Http.js) | `createMcpHttpHandler` (runtime-agnostic Web-standard handler) and `serveMcpHttp` (Bun-only convenience, wraps `Bun.serve`). |
|
|
184
|
+
| [lib/Guard.js](./lib/Guard.js) | `withMetaGuard` — optional per-service token protection; see above. |
|
|
185
|
+
| [lib/Client.js](./lib/Client.js) | `createMcpClient`, `connectStdioClient`, `connectHttpClient` — client-side helpers. |
|
|
186
|
+
| [lib/Gateway.js](./lib/Gateway.js) | `createMcpGateway` — aggregates several already-connected upstream MCP clients into one server. |
|
|
187
|
+
| [lib/Validator.js](./lib/Validator.js) | `empyriaJsonSchemaValidator` — adapts `@empyria/common`'s `createValidator` to the MCP SDK's pluggable JSON Schema validator interface, the same extension point its own `ajv`/`cf-worker` providers use. |
|
|
188
188
|
|
|
189
189
|
There is no official JSON-Schema-only convenience API in `@modelcontextprotocol/server` — its
|
|
190
190
|
`registerTool()` still needs a "Standard Schema" (what Zod produces). What _is_ official and
|
package/lib/Gateway.js
CHANGED
|
@@ -5,7 +5,7 @@ import { McpServer, fromJsonSchema } from '@modelcontextprotocol/server'
|
|
|
5
5
|
* arguments are already validated by the upstream server when the call is forwarded. Re-running
|
|
6
6
|
* a second, independent JSON Schema implementation over the same input here would risk rejecting
|
|
7
7
|
* (or silently reshaping) input the upstream itself considers valid, for zero benefit.
|
|
8
|
-
* @type {import('./Validator.js').
|
|
8
|
+
* @type {import('./Validator.js').empyriaJsonSchemaValidator}
|
|
9
9
|
*/
|
|
10
10
|
const passthroughValidator = {
|
|
11
11
|
getValidator: () => (input) => ({ valid: true, data: input }),
|
package/lib/Server.js
CHANGED
|
@@ -2,7 +2,7 @@ import { McpServer, fromJsonSchema } from '@modelcontextprotocol/server'
|
|
|
2
2
|
|
|
3
3
|
import { defineSchema } from '@empyria/common'
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { empyriaJsonSchemaValidator } from './Validator.js'
|
|
6
6
|
import { withMetaGuard } from './Guard.js'
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -64,10 +64,7 @@ function registerService(server, service) {
|
|
|
64
64
|
// no-params action drops to a single-argument (extra) call instead — silently
|
|
65
65
|
// handing the caller's own context object to `args` and leaving `extra` (and
|
|
66
66
|
// therefore any auth context) undefined.
|
|
67
|
-
config.inputSchema = fromJsonSchema(
|
|
68
|
-
defineSchema(params ?? {}),
|
|
69
|
-
principiaJsonSchemaValidator,
|
|
70
|
-
)
|
|
67
|
+
config.inputSchema = fromJsonSchema(defineSchema(params ?? {}), empyriaJsonSchemaValidator)
|
|
71
68
|
|
|
72
69
|
server.registerTool(`${service.name}.${actionName}`, config, async (args, extra) => {
|
|
73
70
|
const result = await handler(args ?? {}, extra)
|
package/lib/Validator.js
CHANGED
|
@@ -12,10 +12,10 @@ import { createValidator } from '@empyria/common'
|
|
|
12
12
|
* `@modelcontextprotocol/server`'s `fromJsonSchema`), backed by
|
|
13
13
|
* `@empyria/common`'s `createValidator` — no Ajv, no Zod.
|
|
14
14
|
*
|
|
15
|
-
* `createValidator` throws a `
|
|
15
|
+
* `createValidator` throws a `EmpyriaError` on invalid input; this adapts
|
|
16
16
|
* that into the provider's `{valid, data, errorMessage}` result shape.
|
|
17
17
|
*/
|
|
18
|
-
export const
|
|
18
|
+
export const empyriaJsonSchemaValidator = {
|
|
19
19
|
/**
|
|
20
20
|
* @param {Object} schema - A JSON schema (Draft 2020-12-compatible).
|
|
21
21
|
* @returns {(input: unknown) => JsonSchemaValidatorResult}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@empyria/mcp",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "MCP (Model Context Protocol) helpers for the
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "MCP (Model Context Protocol) helpers for the Empyria nanoservice framework",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Imre Fazekas <imre.fazekas@icloud.com>",
|
|
7
7
|
"repository": {
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"test:watch": "bun test --watch"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@empyria/classification": "0.1.
|
|
28
|
-
"@empyria/common": "0.1.
|
|
27
|
+
"@empyria/classification": "0.1.1",
|
|
28
|
+
"@empyria/common": "0.1.1",
|
|
29
29
|
"@modelcontextprotocol/client": "2.0.0",
|
|
30
30
|
"@modelcontextprotocol/server": "2.0.0"
|
|
31
31
|
},
|
package/test/Validator.test.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { describe, test, expect } from 'bun:test'
|
|
2
|
-
import {
|
|
2
|
+
import { empyriaJsonSchemaValidator } from '../lib/Validator.js'
|
|
3
3
|
|
|
4
|
-
describe('
|
|
4
|
+
describe('empyriaJsonSchemaValidator', () => {
|
|
5
5
|
const schema = {
|
|
6
6
|
type: 'object',
|
|
7
7
|
properties: { name: { type: 'string' }, age: { type: 'number', default: 0 } },
|
|
@@ -9,19 +9,19 @@ describe('principiaJsonSchemaValidator', () => {
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
test('getValidator returns a reusable validator function', () => {
|
|
12
|
-
const validate =
|
|
12
|
+
const validate = empyriaJsonSchemaValidator.getValidator(schema)
|
|
13
13
|
expect(typeof validate).toBe('function')
|
|
14
14
|
})
|
|
15
15
|
|
|
16
16
|
test('valid input resolves with the (defaulted) data', () => {
|
|
17
|
-
const validate =
|
|
17
|
+
const validate = empyriaJsonSchemaValidator.getValidator(schema)
|
|
18
18
|
const result = validate({ name: 'Bob' })
|
|
19
19
|
expect(result.valid).toBe(true)
|
|
20
20
|
expect(result.data).toEqual({ name: 'Bob', age: 0 })
|
|
21
21
|
})
|
|
22
22
|
|
|
23
23
|
test('invalid input resolves with an error message, not a throw', () => {
|
|
24
|
-
const validate =
|
|
24
|
+
const validate = empyriaJsonSchemaValidator.getValidator(schema)
|
|
25
25
|
const result = validate({})
|
|
26
26
|
expect(result.valid).toBe(false)
|
|
27
27
|
expect(typeof result.errorMessage).toBe('string')
|