mcp2service 1.0.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/README.md +272 -0
- package/dist/cjs/adapters/factory.js +51901 -0
- package/dist/cjs/adapters/graphql.js +28866 -0
- package/dist/cjs/adapters/grpc.js +36898 -0
- package/dist/cjs/adapters/http.js +28835 -0
- package/dist/cjs/adapters/index.js +51906 -0
- package/dist/cjs/cli.js +2283 -0
- package/dist/cjs/errors.js +88 -0
- package/dist/cjs/index.js +424 -0
- package/dist/cjs/mpc-proxy.js +188884 -0
- package/dist/cjs/types.js +29 -0
- package/dist/cjs/validation.js +13971 -0
- package/dist/cli/cli.js +2272 -0
- package/dist/esm/index.js +424 -0
- package/dist/types/adapters/factory.d.ts +10 -0
- package/dist/types/adapters/graphql.d.ts +28 -0
- package/dist/types/adapters/grpc.d.ts +32 -0
- package/dist/types/adapters/http.d.ts +15 -0
- package/dist/types/adapters/index.d.ts +4 -0
- package/dist/types/cli.d.ts +2 -0
- package/dist/types/errors.d.ts +23 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/mpc-proxy.d.ts +12 -0
- package/dist/types/types.d.ts +45 -0
- package/dist/types/validation.d.ts +49 -0
- package/package.json +96 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ServiceAdapter, AdapterFactory } from '../types';
|
|
2
|
+
export declare class DefaultAdapterFactory implements AdapterFactory {
|
|
3
|
+
private adapterRegistry;
|
|
4
|
+
constructor();
|
|
5
|
+
private registerDefaultAdapters;
|
|
6
|
+
createAdapter(type: string, options: Record<string, any>): ServiceAdapter;
|
|
7
|
+
registerAdapter(type: string, adapterClass: new () => ServiceAdapter): void;
|
|
8
|
+
getSupportedTypes(): string[];
|
|
9
|
+
}
|
|
10
|
+
export declare const defaultAdapterFactory: DefaultAdapterFactory;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { AudioContent, ContentResult, Context, ImageContent, ResourceContent, ResourceLink, TextContent } from 'fastmcp';
|
|
2
|
+
import type { StandardSchemaV1 } from "@standard-schema/spec";
|
|
3
|
+
import type { ServiceAdapter } from '../types';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
export declare const graphqlAdapterConfigSchema: z.ZodObject<{
|
|
6
|
+
endpoint: z.ZodString;
|
|
7
|
+
headers: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
8
|
+
timeout: z.ZodOptional<z.ZodNumber>;
|
|
9
|
+
operationName: z.ZodOptional<z.ZodString>;
|
|
10
|
+
variables: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
11
|
+
retry: z.ZodOptional<z.ZodObject<{
|
|
12
|
+
attempts: z.ZodDefault<z.ZodNumber>;
|
|
13
|
+
backoff: z.ZodDefault<z.ZodNumber>;
|
|
14
|
+
}, z.core.$strip>>;
|
|
15
|
+
}, z.core.$strip>;
|
|
16
|
+
export type GraphQLAdapterConfig = z.infer<typeof graphqlAdapterConfigSchema>;
|
|
17
|
+
export declare class GraphQLAdapter implements ServiceAdapter {
|
|
18
|
+
private adapterConfig;
|
|
19
|
+
private endpoint;
|
|
20
|
+
private headers;
|
|
21
|
+
private timeout?;
|
|
22
|
+
private retryConfig?;
|
|
23
|
+
private operationName?;
|
|
24
|
+
private defaultVariables?;
|
|
25
|
+
config(options: Record<string, any>): void;
|
|
26
|
+
private executeWithRetry;
|
|
27
|
+
call(args: StandardSchemaV1.InferOutput<any>, context: Context<any>): Promise<AudioContent | ContentResult | ImageContent | ResourceContent | ResourceLink | string | TextContent | void>;
|
|
28
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { AudioContent, ContentResult, Context, ImageContent, ResourceContent, ResourceLink, TextContent } from 'fastmcp';
|
|
2
|
+
import type { StandardSchemaV1 } from "@standard-schema/spec";
|
|
3
|
+
import type { ServiceAdapter } from '../types';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
export declare const grpcAdapterConfigSchema: z.ZodObject<{
|
|
6
|
+
protoPath: z.ZodString;
|
|
7
|
+
serviceName: z.ZodString;
|
|
8
|
+
methodName: z.ZodString;
|
|
9
|
+
address: z.ZodString;
|
|
10
|
+
credentials: z.ZodDefault<z.ZodEnum<{
|
|
11
|
+
insecure: "insecure";
|
|
12
|
+
ssl: "ssl";
|
|
13
|
+
}>>;
|
|
14
|
+
timeout: z.ZodOptional<z.ZodNumber>;
|
|
15
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
16
|
+
retry: z.ZodOptional<z.ZodObject<{
|
|
17
|
+
attempts: z.ZodDefault<z.ZodNumber>;
|
|
18
|
+
backoff: z.ZodDefault<z.ZodNumber>;
|
|
19
|
+
}, z.core.$strip>>;
|
|
20
|
+
}, z.core.$strip>;
|
|
21
|
+
export type GrpcAdapterConfig = z.infer<typeof grpcAdapterConfigSchema>;
|
|
22
|
+
export declare class GrpcAdapter implements ServiceAdapter {
|
|
23
|
+
private adapterConfig;
|
|
24
|
+
private client;
|
|
25
|
+
private packageDefinition;
|
|
26
|
+
private proto;
|
|
27
|
+
config(options: Record<string, any>): void;
|
|
28
|
+
private _loadProto;
|
|
29
|
+
private _getClient;
|
|
30
|
+
private executeWithRetry;
|
|
31
|
+
call(args: StandardSchemaV1.InferOutput<any>, context: Context<any>): Promise<AudioContent | ContentResult | ImageContent | ResourceContent | ResourceLink | string | TextContent | void>;
|
|
32
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import 'axios';
|
|
2
|
+
import type { AudioContent, ContentResult, Context, ImageContent, ResourceContent, ResourceLink, TextContent } from 'fastmcp';
|
|
3
|
+
import type { StandardSchemaV1 } from "@standard-schema/spec";
|
|
4
|
+
import type { ServiceAdapter } from '../types';
|
|
5
|
+
export declare class HttpAdapter implements ServiceAdapter {
|
|
6
|
+
private url;
|
|
7
|
+
private method;
|
|
8
|
+
private headers;
|
|
9
|
+
private axiosConfig;
|
|
10
|
+
private timeout?;
|
|
11
|
+
private retryConfig?;
|
|
12
|
+
config(option: Record<string, any>): void;
|
|
13
|
+
private executeWithRetry;
|
|
14
|
+
call(args: StandardSchemaV1.InferOutput<any>, context: Context<any>): Promise<AudioContent | ContentResult | ImageContent | ResourceContent | ResourceLink | string | TextContent | void>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export declare class MCPError extends Error {
|
|
2
|
+
readonly code: string;
|
|
3
|
+
readonly statusCode?: number | undefined;
|
|
4
|
+
readonly details?: Record<string, any> | undefined;
|
|
5
|
+
constructor(message: string, code: string, statusCode?: number | undefined, details?: Record<string, any> | undefined);
|
|
6
|
+
}
|
|
7
|
+
export declare class ValidationError extends MCPError {
|
|
8
|
+
constructor(message: string, details?: Record<string, any>);
|
|
9
|
+
}
|
|
10
|
+
export declare class ConfigurationError extends MCPError {
|
|
11
|
+
constructor(message: string, details?: Record<string, any>);
|
|
12
|
+
}
|
|
13
|
+
export declare class AdapterError extends MCPError {
|
|
14
|
+
readonly adapterName: string;
|
|
15
|
+
constructor(message: string, adapterName: string, details?: Record<string, any>);
|
|
16
|
+
}
|
|
17
|
+
export declare class AuthenticationError extends MCPError {
|
|
18
|
+
constructor(message: string, details?: Record<string, any>);
|
|
19
|
+
}
|
|
20
|
+
export declare class RateLimitError extends MCPError {
|
|
21
|
+
constructor(message: string, details?: Record<string, any>);
|
|
22
|
+
}
|
|
23
|
+
export type ErrorType = 'VALIDATION_ERROR' | 'CONFIGURATION_ERROR' | 'ADAPTER_ERROR' | 'AUTHENTICATION_ERROR' | 'RATE_LIMIT_ERROR' | 'INTERNAL_ERROR';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { FastMCP } from 'fastmcp';
|
|
2
|
+
import * as types from './types';
|
|
3
|
+
export declare class McpProxy {
|
|
4
|
+
server: FastMCP | undefined;
|
|
5
|
+
private _toolhandlers;
|
|
6
|
+
private validatedOptions;
|
|
7
|
+
constructor(options: types.McpOptions);
|
|
8
|
+
_createMcpServer(): void;
|
|
9
|
+
private _registerTool;
|
|
10
|
+
private _convertTransportForFastMCP;
|
|
11
|
+
start(): Promise<void>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import * as http from "http";
|
|
2
|
+
import type { AudioContent, ContentResult, Context, ImageContent, ResourceContent, ResourceLink, TextContent, ToolParameters } from 'fastmcp';
|
|
3
|
+
import type { StandardSchemaV1 } from "@standard-schema/spec";
|
|
4
|
+
import type { EventStore } from "@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js";
|
|
5
|
+
import type { ValidatedMcpOptions as _ValidatedMcpOptions } from './validation';
|
|
6
|
+
type Authenticate<T> = (request: http.IncomingMessage) => Promise<T>;
|
|
7
|
+
export interface McpOptions {
|
|
8
|
+
name: string;
|
|
9
|
+
version: `${number}.${number}.${number}`;
|
|
10
|
+
headers?: Array<string>;
|
|
11
|
+
authedFn?: Authenticate<Record<string, any>>;
|
|
12
|
+
transport: Partial<{
|
|
13
|
+
httpStream: {
|
|
14
|
+
enableJsonResponse?: boolean;
|
|
15
|
+
endpoint?: `/${string}`;
|
|
16
|
+
eventStore?: EventStore;
|
|
17
|
+
host?: string;
|
|
18
|
+
port: number;
|
|
19
|
+
stateless?: boolean;
|
|
20
|
+
};
|
|
21
|
+
transportType: "httpStream" | "stdio";
|
|
22
|
+
}>;
|
|
23
|
+
tools: {
|
|
24
|
+
[toolName: string]: ToolDefine;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export type ValidatedMcpOptions = _ValidatedMcpOptions;
|
|
28
|
+
export interface ToolDefine {
|
|
29
|
+
type: string;
|
|
30
|
+
description?: string;
|
|
31
|
+
params: ToolParameters;
|
|
32
|
+
options: Record<string, any>;
|
|
33
|
+
execute?: ToolFn;
|
|
34
|
+
}
|
|
35
|
+
export type ToolFn = (args: StandardSchemaV1.InferOutput<any>, context: Context<any>) => Promise<AudioContent | ContentResult | ImageContent | ResourceContent | ResourceLink | string | TextContent | void>;
|
|
36
|
+
export interface ServiceAdapter {
|
|
37
|
+
config(option: Record<string, any>): void;
|
|
38
|
+
call: ToolFn;
|
|
39
|
+
}
|
|
40
|
+
export interface AdapterFactory {
|
|
41
|
+
createAdapter(type: string, options: Record<string, any>): ServiceAdapter;
|
|
42
|
+
registerAdapter(type: string, adapterClass: new () => ServiceAdapter): void;
|
|
43
|
+
getSupportedTypes(): string[];
|
|
44
|
+
}
|
|
45
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { IncomingMessage } from 'http';
|
|
3
|
+
export declare const mcpOptionsSchema: z.ZodObject<{
|
|
4
|
+
name: z.ZodString;
|
|
5
|
+
version: z.ZodString;
|
|
6
|
+
headers: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
7
|
+
authedFn: z.ZodOptional<z.ZodCustom<(request: IncomingMessage) => Promise<Record<string, any>>, (request: IncomingMessage) => Promise<Record<string, any>>>>;
|
|
8
|
+
transport: z.ZodObject<{
|
|
9
|
+
httpStream: z.ZodOptional<z.ZodOptional<z.ZodObject<{
|
|
10
|
+
enableJsonResponse: z.ZodOptional<z.ZodBoolean>;
|
|
11
|
+
endpoint: z.ZodOptional<z.ZodString>;
|
|
12
|
+
eventStore: z.ZodOptional<z.ZodAny>;
|
|
13
|
+
host: z.ZodOptional<z.ZodString>;
|
|
14
|
+
port: z.ZodNumber;
|
|
15
|
+
stateless: z.ZodOptional<z.ZodBoolean>;
|
|
16
|
+
}, z.core.$strip>>>;
|
|
17
|
+
transportType: z.ZodOptional<z.ZodOptional<z.ZodEnum<{
|
|
18
|
+
httpStream: "httpStream";
|
|
19
|
+
stdio: "stdio";
|
|
20
|
+
}>>>;
|
|
21
|
+
}, z.core.$strip>;
|
|
22
|
+
tools: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
23
|
+
type: z.ZodString;
|
|
24
|
+
description: z.ZodOptional<z.ZodString>;
|
|
25
|
+
params: z.ZodAny;
|
|
26
|
+
options: z.ZodRecord<z.ZodString, z.ZodAny>;
|
|
27
|
+
execute: z.ZodOptional<z.ZodCustom<(args: any, context: any) => Promise<any>, (args: any, context: any) => Promise<any>>>;
|
|
28
|
+
}, z.core.$strip>>;
|
|
29
|
+
}, z.core.$strict>;
|
|
30
|
+
export declare const toolParamsSchema: z.ZodObject<{}, z.core.$loose>;
|
|
31
|
+
export declare const httpAdapterConfigSchema: z.ZodObject<{
|
|
32
|
+
url: z.ZodString;
|
|
33
|
+
method: z.ZodDefault<z.ZodEnum<{
|
|
34
|
+
GET: "GET";
|
|
35
|
+
POST: "POST";
|
|
36
|
+
PUT: "PUT";
|
|
37
|
+
DELETE: "DELETE";
|
|
38
|
+
PATCH: "PATCH";
|
|
39
|
+
}>>;
|
|
40
|
+
headers: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
41
|
+
timeout: z.ZodOptional<z.ZodNumber>;
|
|
42
|
+
retry: z.ZodOptional<z.ZodObject<{
|
|
43
|
+
attempts: z.ZodDefault<z.ZodNumber>;
|
|
44
|
+
backoff: z.ZodDefault<z.ZodNumber>;
|
|
45
|
+
}, z.core.$strip>>;
|
|
46
|
+
}, z.core.$strip>;
|
|
47
|
+
export declare function validate<T>(schema: z.ZodSchema<T>, data: unknown, context?: string): T;
|
|
48
|
+
export type ValidatedMcpOptions = z.infer<typeof mcpOptionsSchema>;
|
|
49
|
+
export type ValidatedHttpAdapterConfig = z.infer<typeof httpAdapterConfigSchema>;
|
package/package.json
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "mcp2service",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Model Context Protocol代理服务,支持通过多种适配器将工具调用代理到后端服务",
|
|
5
|
+
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/cjs/index.js",
|
|
8
|
+
|
|
9
|
+
"module": "./dist/esm/index.js",
|
|
10
|
+
|
|
11
|
+
"types": "./dist/types/index.d.ts",
|
|
12
|
+
"bin": {
|
|
13
|
+
"mcp2service": "./dist/cli/cli.js"
|
|
14
|
+
},
|
|
15
|
+
"exports": {
|
|
16
|
+
|
|
17
|
+
".": {
|
|
18
|
+
|
|
19
|
+
"import": "./dist/esm/index.js",
|
|
20
|
+
|
|
21
|
+
"require": "./dist/cjs/index.js",
|
|
22
|
+
|
|
23
|
+
"types": "./dist/types/index.d.ts"
|
|
24
|
+
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"dist",
|
|
30
|
+
"README.md"
|
|
31
|
+
],
|
|
32
|
+
"scripts": {
|
|
33
|
+
"start": "bun run index.ts",
|
|
34
|
+
"dev": "bun --watch index.ts",
|
|
35
|
+
"test": "bun test",
|
|
36
|
+
"test:watch": "bun test --watch",
|
|
37
|
+
"lint": "bun run lint:check",
|
|
38
|
+
"lint:check": "eslint . --ext .ts",
|
|
39
|
+
"lint:fix": "eslint . --ext .ts --fix",
|
|
40
|
+
"format": "prettier --write \"**/*.{ts,js,json,md,yaml,yml}\"",
|
|
41
|
+
"cli": "bun run cli.ts",
|
|
42
|
+
"build": "npm run build:cjs && npm run build:esm && npm run build:types && npm run build:cli",
|
|
43
|
+
|
|
44
|
+
"build:cjs": "bun build --outdir dist/cjs --format cjs --target node ./index.ts --minify",
|
|
45
|
+
|
|
46
|
+
"build:esm": "bun build --outdir dist/esm --format esm --target node ./index.ts --minify",
|
|
47
|
+
|
|
48
|
+
"build:types": "tsc --emitDeclarationOnly -d --outdir dist/types",
|
|
49
|
+
|
|
50
|
+
"build:cli": " bun build --outdir dist/cli cli.ts --target node",
|
|
51
|
+
"postbuild": "chmod +x dist/cli/cli.js",
|
|
52
|
+
"prepublishOnly": "npm run build"
|
|
53
|
+
},
|
|
54
|
+
"keywords": [
|
|
55
|
+
"mcp",
|
|
56
|
+
"model-context-protocol",
|
|
57
|
+
"proxy",
|
|
58
|
+
"adapter",
|
|
59
|
+
"http",
|
|
60
|
+
"graphql",
|
|
61
|
+
"grpc"
|
|
62
|
+
],
|
|
63
|
+
"author": "Cheng Guang <kingecg@qq.com>",
|
|
64
|
+
"license": "MIT",
|
|
65
|
+
"repository": {
|
|
66
|
+
"type": "git",
|
|
67
|
+
"url": "https://github.com/your-org/mcp2service.git"
|
|
68
|
+
},
|
|
69
|
+
"bugs": {
|
|
70
|
+
"url": "https://github.com/your-org/mcp2service/issues"
|
|
71
|
+
},
|
|
72
|
+
"homepage": "https://github.com/your-org/mcp2service#readme",
|
|
73
|
+
"devDependencies": {
|
|
74
|
+
"@types/bun": "latest",
|
|
75
|
+
"@types/node": "latest",
|
|
76
|
+
"@typescript-eslint/eslint-plugin": "^7.0.0",
|
|
77
|
+
"@typescript-eslint/parser": "^7.0.0",
|
|
78
|
+
"eslint": "^8.57.0",
|
|
79
|
+
"prettier": "^3.0.0"
|
|
80
|
+
},
|
|
81
|
+
"peerDependencies": {
|
|
82
|
+
"typescript": "^5"
|
|
83
|
+
},
|
|
84
|
+
"dependencies": {
|
|
85
|
+
"@grpc/grpc-js": "^1.14.3",
|
|
86
|
+
"@grpc/proto-loader": "^0.8.0",
|
|
87
|
+
"@valibot/to-json-schema": "^1.5.0",
|
|
88
|
+
"axios": "^1.13.2",
|
|
89
|
+
"commander": "^12.0.0",
|
|
90
|
+
"effect": "^3.19.15",
|
|
91
|
+
"fastmcp": "^3.29.0",
|
|
92
|
+
"sury": "^11.0.0-alpha.4",
|
|
93
|
+
"yaml": "^2.0.0",
|
|
94
|
+
"zod": "^4.3.6"
|
|
95
|
+
}
|
|
96
|
+
}
|