@operad-io/mcp 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +11 -2
- package/package.json +21 -4
- package/src/arguments.ts +91 -0
- package/src/channel.ts +658 -0
- package/src/format.ts +211 -0
- package/src/index.ts +39 -0
- package/src/policy.ts +93 -0
- package/src/server.ts +558 -0
- package/src/stdio.ts +22 -0
- package/src/tools.ts +627 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Yinghai Zhao
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @operad-io/mcp
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**The MCP server and channel.** `operad mcp` is an MCP server on stdio. A lead agent such as Claude Code reads pending, running and history, runs plugin commands and takes the actions `config.json` allows. It never takes your decision.
|
|
4
|
+
|
|
5
|
+
This package is part of [operad](https://github.com/operad-io/operad). Most people install only [`@operad-io/cli`](https://www.npmjs.com/package/@operad-io/cli).
|
|
6
|
+
|
|
7
|
+
## Documentation
|
|
8
|
+
|
|
9
|
+
- User guide: [docs/user/mcp.md](https://github.com/operad-io/operad/blob/main/docs/user/mcp.md)
|
|
10
|
+
- Website: <https://operad.io>
|
|
11
|
+
|
|
12
|
+
MIT licensed.
|
package/package.json
CHANGED
|
@@ -1,6 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@operad-io/mcp",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": "./src/index.ts",
|
|
7
|
+
"./stdio": "./src/stdio.ts"
|
|
8
|
+
},
|
|
9
|
+
"dependencies": {
|
|
10
|
+
"@operad-io/engine": "0.1.0"
|
|
11
|
+
},
|
|
12
|
+
"description": "operad: the MCP server and channel",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/operad-io/operad.git",
|
|
16
|
+
"directory": "packages/mcp"
|
|
17
|
+
},
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"files": [
|
|
20
|
+
"src",
|
|
21
|
+
"LICENSE"
|
|
22
|
+
]
|
|
23
|
+
}
|
package/src/arguments.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/** Checking a tool call's arguments against the small JSON Schema it declares. */
|
|
2
|
+
|
|
3
|
+
import type { InputPropertySchema, InputSchema } from "./tools.ts";
|
|
4
|
+
import { isRecord } from "@operad-io/engine";
|
|
5
|
+
|
|
6
|
+
/** The arguments do not match the tool's input schema. */
|
|
7
|
+
export class InvalidToolArguments extends Error {
|
|
8
|
+
constructor(message: string) {
|
|
9
|
+
super(message);
|
|
10
|
+
this.name = "InvalidToolArguments";
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function checkOne(
|
|
15
|
+
name: string,
|
|
16
|
+
property: InputPropertySchema,
|
|
17
|
+
value: unknown,
|
|
18
|
+
): void {
|
|
19
|
+
if (property.type === "string") {
|
|
20
|
+
if (typeof value !== "string") {
|
|
21
|
+
throw new InvalidToolArguments(`argument "${name}" must be a string`);
|
|
22
|
+
}
|
|
23
|
+
if (property.minLength !== undefined && value.length < property.minLength) {
|
|
24
|
+
throw new InvalidToolArguments(
|
|
25
|
+
`argument "${name}" must be at least ${property.minLength} character${property.minLength === 1 ? "" : "s"}`,
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (property.type === "boolean") {
|
|
31
|
+
if (typeof value !== "boolean") {
|
|
32
|
+
throw new InvalidToolArguments(`argument "${name}" must be a boolean`);
|
|
33
|
+
}
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (property.type === "integer") {
|
|
37
|
+
if (typeof value !== "number" || !Number.isInteger(value)) {
|
|
38
|
+
throw new InvalidToolArguments(`argument "${name}" must be an integer`);
|
|
39
|
+
}
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (property.type === "array") {
|
|
43
|
+
if (!Array.isArray(value)) {
|
|
44
|
+
throw new InvalidToolArguments(`argument "${name}" must be an array`);
|
|
45
|
+
}
|
|
46
|
+
if (property.items !== undefined) {
|
|
47
|
+
for (const [index, item] of value.entries()) {
|
|
48
|
+
checkOne(`${name}[${index}]`, property.items, item);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (property.type === "object") {
|
|
54
|
+
if (!isRecord(value)) {
|
|
55
|
+
throw new InvalidToolArguments(`argument "${name}" must be an object`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Returns the arguments a tool receives, or throws when one is missing, of the
|
|
62
|
+
* wrong type, or not declared by its schema.
|
|
63
|
+
*/
|
|
64
|
+
export function validateArguments(
|
|
65
|
+
schema: InputSchema,
|
|
66
|
+
value: unknown,
|
|
67
|
+
): Record<string, unknown> {
|
|
68
|
+
if (!isRecord(value)) {
|
|
69
|
+
throw new InvalidToolArguments("arguments must be an object");
|
|
70
|
+
}
|
|
71
|
+
const properties = schema.properties;
|
|
72
|
+
const known = new Set(Object.keys(properties));
|
|
73
|
+
for (const key of Object.keys(value)) {
|
|
74
|
+
if (!known.has(key)) {
|
|
75
|
+
throw new InvalidToolArguments(`unknown argument "${key}"`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
for (const name of schema.required ?? []) {
|
|
79
|
+
if (!Object.prototype.hasOwnProperty.call(value, name)) {
|
|
80
|
+
throw new InvalidToolArguments(`missing required argument "${name}"`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
const result: Record<string, unknown> = {};
|
|
84
|
+
for (const [name, property] of Object.entries(properties)) {
|
|
85
|
+
if (!Object.prototype.hasOwnProperty.call(value, name)) continue;
|
|
86
|
+
const item = value[name];
|
|
87
|
+
checkOne(name, property, item);
|
|
88
|
+
result[name] = item;
|
|
89
|
+
}
|
|
90
|
+
return result;
|
|
91
|
+
}
|