@usekova/mcp-server 0.1.0 → 2.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 ADDED
@@ -0,0 +1,57 @@
1
+ # @usekova/mcp-server
2
+
3
+ Model Context Protocol (MCP) server that exposes Stele covenant operations as tools to any AI agent via JSON-RPC 2.0.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @usekova/mcp-server
9
+ ```
10
+
11
+ ## Key APIs
12
+
13
+ - **SteleServer**: MCP server class that handles JSON-RPC 2.0 messages and exposes Stele tools. Supports `initialize`, `tools/list`, `tools/call`, and `ping` methods.
14
+ - **createAuthMiddleware()**: Authentication middleware for securing MCP endpoints.
15
+ - **JSON_RPC_ERRORS**: Standard JSON-RPC 2.0 error code constants.
16
+
17
+ ### Exposed Tools
18
+
19
+ | Tool | Description |
20
+ |------|-------------|
21
+ | `create_covenant` | Create a signed covenant document with CCL constraints |
22
+ | `verify_covenant` | Verify a covenant document (signature, expiry, CCL syntax) |
23
+ | `evaluate_action` | Check if an action on a resource is permitted by a covenant |
24
+ | `create_identity` | Create an agent identity with model attestation and capabilities |
25
+ | `parse_ccl` | Parse CCL source text into a structured document |
26
+ | `list_covenants` | List stored covenants with optional issuer/beneficiary filters |
27
+
28
+ ## Usage
29
+
30
+ ```typescript
31
+ import { SteleServer } from '@usekova/mcp-server';
32
+ import { MemoryStore } from '@usekova/store';
33
+
34
+ const server = new SteleServer(new MemoryStore(), {
35
+ name: 'my-stele-server',
36
+ version: '1.0.0',
37
+ });
38
+
39
+ // Handle a JSON-RPC message
40
+ const response = await server.handleMessage({
41
+ jsonrpc: '2.0',
42
+ id: 1,
43
+ method: 'tools/list',
44
+ params: {},
45
+ });
46
+
47
+ // Call a tool directly
48
+ const result = await server.callTool('evaluate_action', {
49
+ covenantId: 'abc123',
50
+ action: 'read',
51
+ resource: '/data',
52
+ });
53
+ ```
54
+
55
+ ## Docs
56
+
57
+ See the [Stele SDK root documentation](../../README.md) for the full API reference.
package/dist/auth.d.ts ADDED
@@ -0,0 +1,51 @@
1
+ /**
2
+ * MCP Server authentication middleware.
3
+ *
4
+ * Provides API key authentication, Ed25519 signature-based authentication,
5
+ * per-client rate limiting, and key revocation for the MCP server.
6
+ *
7
+ * @packageDocumentation
8
+ */
9
+ /**
10
+ * Options for configuring the authentication middleware.
11
+ */
12
+ export interface MCPAuthOptions {
13
+ /** List of valid API keys for API key authentication. */
14
+ apiKeys?: string[];
15
+ /** Hex-encoded Ed25519 public keys trusted for signature-based authentication. */
16
+ trustedKeys?: string[];
17
+ /** Maximum number of requests per client per minute. */
18
+ rateLimitPerMinute?: number;
19
+ }
20
+ /**
21
+ * Represents an authenticated client request.
22
+ */
23
+ export interface AuthenticatedRequest {
24
+ /** Unique identifier for the client. */
25
+ clientId: string;
26
+ /** The authentication method used. */
27
+ authMethod: 'api-key' | 'signature' | 'none';
28
+ /** ISO 8601 timestamp when the authentication was performed. */
29
+ timestamp: string;
30
+ }
31
+ /**
32
+ * Create an authentication middleware for the MCP server.
33
+ *
34
+ * Supports three authentication modes:
35
+ * 1. **API key**: Client provides an `x-api-key` header.
36
+ * 2. **Signature**: Client provides `x-public-key`, `x-signature`, and
37
+ * `x-signature-payload` headers. The payload is verified against the
38
+ * trusted public keys.
39
+ * 3. **None**: If no authentication options are configured, all requests
40
+ * are allowed without authentication.
41
+ *
42
+ * @param options - Authentication configuration options.
43
+ * @returns An object with `authenticate`, `isRateLimited`, `revokeKey`, and `listClients` methods.
44
+ */
45
+ export declare function createAuthMiddleware(options: MCPAuthOptions): {
46
+ authenticate(headers: Record<string, string>): AuthenticatedRequest;
47
+ isRateLimited(clientId: string): boolean;
48
+ revokeKey(key: string): void;
49
+ listClients(): string[];
50
+ };
51
+ //# sourceMappingURL=auth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AASH;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,yDAAyD;IACzD,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,kFAAkF;IAClF,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,wDAAwD;IACxD,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,wCAAwC;IACxC,QAAQ,EAAE,MAAM,CAAC;IACjB,sCAAsC;IACtC,UAAU,EAAE,SAAS,GAAG,WAAW,GAAG,MAAM,CAAC;IAC7C,gEAAgE;IAChE,SAAS,EAAE,MAAM,CAAC;CACnB;AAUD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,cAAc,GAAG;IAC7D,YAAY,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,oBAAoB,CAAC;IACpE,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;IACzC,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,WAAW,IAAI,MAAM,EAAE,CAAC;CACzB,CAoJA"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=auth.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.test.d.ts","sourceRoot":"","sources":["../src/auth.test.ts"],"names":[],"mappings":""}
package/dist/bin.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Stele MCP Server — stdio transport.
4
+ *
5
+ * Reads newline-delimited JSON-RPC 2.0 messages from stdin,
6
+ * dispatches them to the SteleServer, and writes responses to stdout.
7
+ *
8
+ * Usage:
9
+ * npx stele-mcp
10
+ * echo '{"jsonrpc":"2.0","method":"initialize","id":1}' | npx stele-mcp
11
+ */
12
+ export {};
13
+ //# sourceMappingURL=bin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bin.d.ts","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":";AACA;;;;;;;;;GASG"}
@@ -0,0 +1,112 @@
1
+ /**
2
+ * MCP Server Certification system.
3
+ *
4
+ * Proactively certifies MCP servers with trust reports and a badge system.
5
+ * Evaluates servers against a set of criteria and assigns a badge level
6
+ * (none, bronze, silver, gold, platinum) based on the resulting score.
7
+ *
8
+ * @packageDocumentation
9
+ */
10
+ /** Badge levels awarded to MCP servers based on certification score. */
11
+ export type BadgeLevel = 'none' | 'bronze' | 'silver' | 'gold' | 'platinum';
12
+ /** Profile describing an MCP server's identity and capabilities. */
13
+ export interface MCPServerProfile {
14
+ /** Unique identifier for the server. */
15
+ serverId: string;
16
+ /** Human-readable server name. */
17
+ serverName: string;
18
+ /** Server version string. */
19
+ version: string;
20
+ /** List of capabilities the server supports. */
21
+ capabilities: string[];
22
+ /** Timestamp when the server was first registered (ms since epoch). */
23
+ registeredAt: number;
24
+ /** Timestamp when the server was last audited (ms since epoch). */
25
+ lastAuditedAt: number;
26
+ }
27
+ /** Criteria used to evaluate an MCP server for certification. */
28
+ export interface CertificationCriteria {
29
+ /** Whether the server has a covenant defined. */
30
+ covenantDefined: boolean;
31
+ /** Whether the server's identity has been verified. */
32
+ identityVerified: boolean;
33
+ /** Whether attestation is enabled. */
34
+ attestationEnabled: boolean;
35
+ /** The enforcement mode in use. */
36
+ enforcementMode: 'enforce' | 'audit' | 'none';
37
+ /** Server uptime percentage (0-100). */
38
+ uptimePercentage: number;
39
+ /** 95th-percentile response time in milliseconds. */
40
+ responseTimeP95Ms: number;
41
+ /** Whether the server has passed a security audit. */
42
+ securityAuditPassed: boolean;
43
+ /** Whether documentation is complete. */
44
+ documentationComplete: boolean;
45
+ }
46
+ /** The result of evaluating an MCP server against certification criteria. */
47
+ export interface ServerCertification {
48
+ /** The server profile. */
49
+ profile: MCPServerProfile;
50
+ /** The criteria used for evaluation. */
51
+ criteria: CertificationCriteria;
52
+ /** The badge level awarded. */
53
+ badge: BadgeLevel;
54
+ /** The numeric score (0-100). */
55
+ score: number;
56
+ /** Human-readable trust report. */
57
+ report: string;
58
+ /** Timestamp when the certification was issued (ms since epoch). */
59
+ certifiedAt: number;
60
+ /** Timestamp when the certification expires (ms since epoch). */
61
+ expiresAt: number;
62
+ }
63
+ /**
64
+ * Create a new MCP server profile.
65
+ *
66
+ * @param params - Profile parameters.
67
+ * @returns A complete MCPServerProfile with timestamps set to now.
68
+ */
69
+ export declare function createServerProfile(params: {
70
+ serverId: string;
71
+ serverName: string;
72
+ version: string;
73
+ capabilities: string[];
74
+ }): MCPServerProfile;
75
+ /**
76
+ * Evaluate an MCP server against certification criteria and produce
77
+ * a full ServerCertification including badge, score, and report.
78
+ *
79
+ * @param profile - The server profile to evaluate.
80
+ * @param criteria - The certification criteria.
81
+ * @returns A complete ServerCertification.
82
+ */
83
+ export declare function evaluateServer(profile: MCPServerProfile, criteria: CertificationCriteria): ServerCertification;
84
+ /**
85
+ * Generate an aggregate trust report across multiple server certifications.
86
+ *
87
+ * @param certifications - Array of server certifications to analyze.
88
+ * @returns An aggregate trust report with distributions and recommendations.
89
+ */
90
+ export declare function generateTrustReport(certifications: ServerCertification[]): {
91
+ totalServers: number;
92
+ certifiedServers: number;
93
+ averageScore: number;
94
+ badgeDistribution: Record<BadgeLevel, number>;
95
+ topServers: Array<{
96
+ serverId: string;
97
+ score: number;
98
+ badge: BadgeLevel;
99
+ }>;
100
+ recommendations: string[];
101
+ };
102
+ /**
103
+ * Renew a server certification with updated criteria.
104
+ *
105
+ * Re-evaluates the server with the new criteria and updates timestamps.
106
+ *
107
+ * @param cert - The existing certification to renew.
108
+ * @param newCriteria - The updated certification criteria.
109
+ * @returns A new ServerCertification with fresh timestamps and score.
110
+ */
111
+ export declare function renewCertification(cert: ServerCertification, newCriteria: CertificationCriteria): ServerCertification;
112
+ //# sourceMappingURL=certification.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"certification.d.ts","sourceRoot":"","s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AAM,CAAC;IACpB,iEAAiE;IACjE,SAAS,EAAE,MAAM,CAAC;CACnB;AAkBD;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE;IAC1C,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,EAAE,CAAC;CACxB,GAAG,gBAAgB,CAUnB;AAkGD;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAC5B,OAAO,EAAE,gBAAgB,EACzB,QAAQ,EAAE,qBAAqB,GAC9B,mBAAmB,CAerB;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,cAAc,EAAE,mBAAmB,EAAE,GAAG;IAC1E,YAAY,EAAE,MAAM,CAAC;IACrB,gBAAgB,EAAE,MAAM,CAAC;IACzB,YAAY,EAAE,MAAM,CAAC;IACrB,iBAAiB,EAAE,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IAC9C,UAAU,EAAE,KAAK,CAAC;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,UAAU,CAAA;KAAE,CAAC,CAAC;IAC1E,eAAe,EAAE,MAAM,EAAE,CAAC;CAC3B,CAiFA;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,mBAAmB,EACzB,WAAW,EAAE,qBAAqB,GACjC,mBAAmB,CAOrB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=certification.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"certification.test.d.ts","sourceRoot":"","sources":["../src/certification.test.ts"],"names":[],"mappings":""}
package/dist/index.d.ts CHANGED
@@ -1,8 +1,68 @@
1
1
  /**
2
- * @stele/mcp-server Model Context Protocol server that exposes
2
+ * @usekova/mcp-server -- Model Context Protocol server that exposes
3
3
  * Stele tools to any AI agent.
4
4
  *
5
+ * Implements JSON-RPC 2.0 over stdio, with tool definitions that map
6
+ * to @usekova/sdk, @usekova/store, and @usekova/crypto operations.
7
+ *
5
8
  * @packageDocumentation
6
9
  */
7
- export {};
10
+ import { MemoryStore } from '@usekova/store';
11
+ import type { JsonRpcRequest, JsonRpcResponse, ToolDefinition, ToolResult, MCPServerOptions } from './types';
12
+ export type { JsonRpcRequest, JsonRpcResponse, JsonRpcSuccessResponse, JsonRpcErrorResponse, JsonRpcErrorDetail, ToolDefinition, ToolResult, ToolResultContent, ToolInputSchema, MCPServerOptions, } from './types';
13
+ export { JSON_RPC_ERRORS } from './types';
14
+ export { createAuthMiddleware } from './auth';
15
+ export type { MCPAuthOptions, AuthenticatedRequest } from './auth';
16
+ /**
17
+ * MCP server that exposes Stele protocol operations as tools via JSON-RPC 2.0.
18
+ *
19
+ * Accepts a {@link MemoryStore} for persisting covenant documents and provides
20
+ * methods for handling MCP protocol messages, listing tools, and calling tools.
21
+ */
22
+ export declare class SteleServer {
23
+ /** The backing store for covenant documents. */
24
+ readonly store: MemoryStore;
25
+ /** The SDK client used for operations. */
26
+ private readonly client;
27
+ /** Server name. */
28
+ readonly name: string;
29
+ /** Server version. */
30
+ readonly version: string;
31
+ constructor(store: MemoryStore, options?: MCPServerOptions);
32
+ /**
33
+ * Return all available tool definitions with their JSON Schema input schemas.
34
+ */
35
+ listTools(): ToolDefinition[];
36
+ /**
37
+ * Call a named tool with the given arguments.
38
+ *
39
+ * @param name - The tool name (must match one of the tool definitions).
40
+ * @param args - The tool arguments matching the tool's input schema.
41
+ * @returns A {@link ToolResult} containing the output or error.
42
+ */
43
+ callTool(name: string, args: Record<string, unknown>): Promise<ToolResult>;
44
+ /**
45
+ * Handle a JSON-RPC 2.0 message and return the appropriate response.
46
+ *
47
+ * Supports the following MCP methods:
48
+ * - `initialize` -- Returns server info and capabilities
49
+ * - `tools/list` -- Returns available tool definitions
50
+ * - `tools/call` -- Executes a tool and returns the result
51
+ * - `ping` -- Returns a pong
52
+ *
53
+ * @param message - A parsed JSON-RPC request object.
54
+ * @returns A JSON-RPC response object.
55
+ */
56
+ handleMessage(message: JsonRpcRequest): Promise<JsonRpcResponse>;
57
+ private _createCovenant;
58
+ private _verifyCovenant;
59
+ private _evaluateAction;
60
+ private _createIdentity;
61
+ private _parseCCL;
62
+ private _listCovenants;
63
+ private _successResponse;
64
+ private _errorResponse;
65
+ private _toolSuccess;
66
+ private _toolError;
67
+ }
8
68
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAI7C,OAAO,KAAK,EACV,cAAc,EACd,eAAe,EAIf,cAAc,EACd,UAAU,EAGV,gBAAgB,EACjB,MAAM,SAAS,CAAC;AAOjB,YAAY,EACV,cAAc,EACd,eAAe,EACf,sBAAsB,EACtB,oBAAoB,EACpB,kBAAkB,EAClB,cAAc,EACd,UAAU,EACV,iBAAiB,EACjB,eAAe,EACf,gBAAgB,GACjB,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE1C,OAAO,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAAC;AAC9C,YAAY,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAAC;AAmKnE;;;;;GAKG;AACH,qBAAa,WAAW;IACtB,gDAAgD;IAChD,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC;IAE5B,0CAA0C;IAC1C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAa;IAEpC,mBAAmB;IACnB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,sBAAsB;I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