counsel-mcp-server 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/dist/client.d.ts +1 -7
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +8 -13
- package/dist/client.js.map +1 -1
- package/dist/index.js +14 -111
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/client.d.ts
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
import { AxiosInstance } from 'axios';
|
|
2
|
-
import { AsyncLocalStorage } from 'async_hooks';
|
|
3
|
-
interface RequestContext {
|
|
4
|
-
token: string;
|
|
5
|
-
}
|
|
6
|
-
export declare const requestContext: AsyncLocalStorage<RequestContext>;
|
|
7
2
|
/**
|
|
8
3
|
* Pre-configured Axios client for Counsel API calls.
|
|
9
|
-
*
|
|
4
|
+
* Uses COUNSEL_API_KEY environment variable for authentication.
|
|
10
5
|
*/
|
|
11
6
|
export declare const apiClient: AxiosInstance;
|
|
12
|
-
export {};
|
|
13
7
|
//# sourceMappingURL=client.d.ts.map
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAU7C;;;GAGG;AACH,eAAO,MAAM,SAAS,EAAE,aAOtB,CAAC"}
|
package/dist/client.js
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
|
-
import { AsyncLocalStorage } from 'async_hooks';
|
|
3
2
|
import { config } from './config.js';
|
|
4
|
-
export const requestContext = new AsyncLocalStorage();
|
|
5
3
|
/**
|
|
6
|
-
* Get
|
|
4
|
+
* Get API key from environment variable
|
|
7
5
|
*/
|
|
8
|
-
function
|
|
9
|
-
return
|
|
6
|
+
function getApiKey() {
|
|
7
|
+
return process.env.COUNSEL_API_KEY;
|
|
10
8
|
}
|
|
11
9
|
/**
|
|
12
10
|
* Pre-configured Axios client for Counsel API calls.
|
|
13
|
-
*
|
|
11
|
+
* Uses COUNSEL_API_KEY environment variable for authentication.
|
|
14
12
|
*/
|
|
15
13
|
export const apiClient = axios.create({
|
|
16
14
|
baseURL: config.COUNSEL_API_URL,
|
|
@@ -20,14 +18,11 @@ export const apiClient = axios.create({
|
|
|
20
18
|
'User-Agent': 'counsel-mcp-server/0.1.0'
|
|
21
19
|
}
|
|
22
20
|
});
|
|
23
|
-
// Add request interceptor to inject the auth token
|
|
21
|
+
// Add request interceptor to inject the auth token
|
|
24
22
|
apiClient.interceptors.request.use(async (reqConfig) => {
|
|
25
|
-
const
|
|
26
|
-
if (
|
|
27
|
-
reqConfig.headers.Authorization = `Bearer ${
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
console.warn("Auth Warning: No token in request context. API call may fail.");
|
|
23
|
+
const apiKey = getApiKey();
|
|
24
|
+
if (apiKey) {
|
|
25
|
+
reqConfig.headers.Authorization = `Bearer ${apiKey}`;
|
|
31
26
|
}
|
|
32
27
|
return reqConfig;
|
|
33
28
|
});
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAwB,MAAM,OAAO,CAAC;AAC7C,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAwB,MAAM,OAAO,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC;;GAEG;AACH,SAAS,SAAS;IAChB,OAAO,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC;AACrC,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,SAAS,GAAkB,KAAK,CAAC,MAAM,CAAC;IACnD,OAAO,EAAE,MAAM,CAAC,eAAe;IAC/B,OAAO,EAAE,KAAK;IACd,OAAO,EAAE;QACP,cAAc,EAAE,kBAAkB;QAClC,YAAY,EAAE,0BAA0B;KACzC;CACF,CAAC,CAAC;AAEH,mDAAmD;AACnD,SAAS,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE;IACrD,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;IAC3B,IAAI,MAAM,EAAE,CAAC;QACX,SAAS,CAAC,OAAO,CAAC,aAAa,GAAG,UAAU,MAAM,EAAE,CAAC;IACvD,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,133 +1,36 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import express from "express";
|
|
3
2
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
4
|
-
import {
|
|
5
|
-
import { ProxyOAuthServerProvider } from "@modelcontextprotocol/sdk/server/auth/providers/proxyProvider.js";
|
|
6
|
-
import { mcpAuthRouter } from "@modelcontextprotocol/sdk/server/auth/router.js";
|
|
7
|
-
import { requireBearerAuth } from "@modelcontextprotocol/sdk/server/auth/middleware/bearerAuth.js";
|
|
3
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
8
4
|
import { Command } from "commander";
|
|
9
|
-
import { randomUUID } from "crypto";
|
|
10
5
|
import { config } from "./config.js";
|
|
11
|
-
import { requestContext } from "./client.js";
|
|
12
6
|
import { TOOLS as DEBATE_TOOLS } from "./tools/debates.js";
|
|
13
7
|
import { TOOLS as ADVISOR_TOOLS } from "./tools/advisor.js";
|
|
14
8
|
const program = new Command();
|
|
15
9
|
program
|
|
16
10
|
.name("counsel-mcp")
|
|
17
|
-
.description("Counsel MCP Server
|
|
18
|
-
.version("0.1.
|
|
11
|
+
.description("Counsel MCP Server")
|
|
12
|
+
.version("0.1.1");
|
|
19
13
|
program.command("start")
|
|
20
|
-
.description("Start the MCP server (
|
|
21
|
-
.
|
|
22
|
-
.option("-h, --host <host>", "Host to bind to", "localhost")
|
|
23
|
-
.action(async (options) => {
|
|
24
|
-
const port = parseInt(options.port, 10);
|
|
25
|
-
const host = options.host;
|
|
26
|
-
const baseUrl = new URL(`http://${host}:${port}`);
|
|
27
|
-
// Use Counsel API as the upstream OAuth server
|
|
28
|
-
const counselApiUrl = config.COUNSEL_API_URL;
|
|
29
|
-
// Create OAuth provider that proxies to Counsel API
|
|
30
|
-
const oauthProvider = new ProxyOAuthServerProvider({
|
|
31
|
-
endpoints: {
|
|
32
|
-
authorizationUrl: `${counselApiUrl}/oauth/authorize`,
|
|
33
|
-
tokenUrl: `${counselApiUrl}/oauth/token`,
|
|
34
|
-
registrationUrl: `${counselApiUrl}/oauth/register`,
|
|
35
|
-
revocationUrl: `${counselApiUrl}/oauth/revoke`,
|
|
36
|
-
},
|
|
37
|
-
// Verify access tokens by calling Counsel API
|
|
38
|
-
verifyAccessToken: async (token) => {
|
|
39
|
-
// For now, we trust the token and extract info from it
|
|
40
|
-
// In production, you might want to call an introspection endpoint
|
|
41
|
-
// or validate the token format
|
|
42
|
-
return {
|
|
43
|
-
token,
|
|
44
|
-
clientId: "counsel-mcp-client",
|
|
45
|
-
scopes: ["counsel:read", "counsel:write"],
|
|
46
|
-
expiresAt: Math.floor(Date.now() / 1000) + 3600, // 1 hour from now
|
|
47
|
-
};
|
|
48
|
-
},
|
|
49
|
-
// Get client info - for proxy mode, we delegate to upstream
|
|
50
|
-
getClient: async (clientId) => {
|
|
51
|
-
// Return minimal client info - actual validation happens at Counsel API
|
|
52
|
-
return {
|
|
53
|
-
client_id: clientId,
|
|
54
|
-
redirect_uris: [],
|
|
55
|
-
grant_types: ["authorization_code", "refresh_token"],
|
|
56
|
-
response_types: ["code"],
|
|
57
|
-
token_endpoint_auth_method: "client_secret_post",
|
|
58
|
-
};
|
|
59
|
-
},
|
|
60
|
-
});
|
|
61
|
-
// Create Express app
|
|
62
|
-
const app = express();
|
|
63
|
-
app.use(express.json());
|
|
64
|
-
// Mount OAuth routes at root (handles /authorize, /token, /register, /.well-known/*)
|
|
65
|
-
app.use(mcpAuthRouter({
|
|
66
|
-
provider: oauthProvider,
|
|
67
|
-
issuerUrl: baseUrl,
|
|
68
|
-
baseUrl: baseUrl,
|
|
69
|
-
scopesSupported: ["counsel:read", "counsel:write"],
|
|
70
|
-
serviceDocumentationUrl: new URL("https://counsel.getmason.dev/docs"),
|
|
71
|
-
}));
|
|
14
|
+
.description("Start the MCP server (stdio mode)")
|
|
15
|
+
.action(async () => {
|
|
72
16
|
// Create MCP server
|
|
73
|
-
const
|
|
17
|
+
const server = new McpServer({
|
|
74
18
|
name: "counsel-mcp",
|
|
75
19
|
version: "0.1.0",
|
|
76
20
|
});
|
|
77
21
|
// Register all tools
|
|
78
22
|
for (const tool of Object.values(DEBATE_TOOLS)) {
|
|
79
|
-
|
|
23
|
+
server.tool(tool.name, tool.schema, tool.handler);
|
|
80
24
|
}
|
|
81
25
|
for (const tool of Object.values(ADVISOR_TOOLS)) {
|
|
82
|
-
|
|
26
|
+
server.tool(tool.name, tool.schema, tool.handler);
|
|
83
27
|
}
|
|
84
|
-
//
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
requiredScopes: ["counsel:read"],
|
|
91
|
-
}));
|
|
92
|
-
// Handle MCP requests
|
|
93
|
-
mcpHandler.all("/", async (req, res) => {
|
|
94
|
-
// Get the auth token from the request (set by requireBearerAuth middleware)
|
|
95
|
-
const authInfo = req.auth;
|
|
96
|
-
const token = authInfo?.token;
|
|
97
|
-
// Run the request within the auth context so tools can access the token
|
|
98
|
-
await requestContext.run({ token }, async () => {
|
|
99
|
-
// Get or create session
|
|
100
|
-
const sessionId = req.headers["mcp-session-id"] || randomUUID();
|
|
101
|
-
let transport = transports.get(sessionId);
|
|
102
|
-
if (!transport) {
|
|
103
|
-
transport = new StreamableHTTPServerTransport({
|
|
104
|
-
sessionIdGenerator: () => sessionId,
|
|
105
|
-
});
|
|
106
|
-
transports.set(sessionId, transport);
|
|
107
|
-
// Connect transport to MCP server
|
|
108
|
-
await mcpServer.connect(transport);
|
|
109
|
-
// Clean up on close
|
|
110
|
-
transport.onclose = () => {
|
|
111
|
-
transports.delete(sessionId);
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
// Handle the request
|
|
115
|
-
await transport.handleRequest(req, res);
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
app.use("/mcp", mcpHandler);
|
|
119
|
-
// Health check endpoint
|
|
120
|
-
app.get("/health", (_req, res) => {
|
|
121
|
-
res.json({ status: "ok", version: "0.1.0" });
|
|
122
|
-
});
|
|
123
|
-
// Start server
|
|
124
|
-
app.listen(port, host, () => {
|
|
125
|
-
console.log(`Counsel MCP Server running at ${baseUrl.href}`);
|
|
126
|
-
console.log(`MCP endpoint: ${baseUrl.href}mcp`);
|
|
127
|
-
console.log(`OAuth authorize: ${baseUrl.href}authorize`);
|
|
128
|
-
console.log(`OAuth metadata: ${baseUrl.href}.well-known/oauth-authorization-server`);
|
|
129
|
-
console.log(`\nUpstream Counsel API: ${counselApiUrl}`);
|
|
130
|
-
});
|
|
28
|
+
// Connect via stdio transport
|
|
29
|
+
const transport = new StdioServerTransport();
|
|
30
|
+
await server.connect(transport);
|
|
31
|
+
// Log to stderr (stdout is used for MCP protocol)
|
|
32
|
+
console.error(`Counsel MCP Server started (stdio mode)`);
|
|
33
|
+
console.error(`Upstream API: ${config.COUNSEL_API_URL}`);
|
|
131
34
|
});
|
|
132
35
|
// Default command is start
|
|
133
36
|
if (process.argv.length === 2) {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,KAAK,IAAI,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,KAAK,IAAI,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAE5D,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;AAE9B,OAAO;KACJ,IAAI,CAAC,aAAa,CAAC;KACnB,WAAW,CAAC,oBAAoB,CAAC;KACjC,OAAO,CAAC,OAAO,CAAC,CAAC;AAEpB,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC;KACrB,WAAW,CAAC,mCAAmC,CAAC;KAChD,MAAM,CAAC,KAAK,IAAI,EAAE;IACjB,oBAAoB;IACpB,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC;QAC3B,IAAI,EAAE,aAAa;QACnB,OAAO,EAAE,OAAO;KACjB,CAAC,CAAC;IAEH,qBAAqB;IACrB,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,CAAC;QAC/C,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IACpD,CAAC;IACD,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,CAAC;QAChD,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IACpD,CAAC;IAED,8BAA8B;IAC9B,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;IAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAEhC,kDAAkD;IAClD,OAAO,CAAC,KAAK,CAAC,yCAAyC,CAAC,CAAC;IACzD,OAAO,CAAC,KAAK,CAAC,iBAAiB,MAAM,CAAC,eAAe,EAAE,CAAC,CAAC;AAC3D,CAAC,CAAC,CAAC;AAEL,2BAA2B;AAC3B,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;IAC9B,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AAC7B,CAAC;AAED,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "counsel-mcp-server",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Open-source MCP server for connecting AI agents to the Counsel API",
|
|
5
5
|
"author": "Counsel AI",
|
|
6
6
|
"license": "MIT",
|
|
@@ -49,12 +49,12 @@
|
|
|
49
49
|
],
|
|
50
50
|
"repository": {
|
|
51
51
|
"type": "git",
|
|
52
|
-
"url": "git+https://github.com/
|
|
52
|
+
"url": "git+https://github.com/mercurialsolo/counsel-mcp.git"
|
|
53
53
|
},
|
|
54
54
|
"bugs": {
|
|
55
|
-
"url": "https://github.com/
|
|
55
|
+
"url": "https://github.com/mercurialsolo/counsel-mcp/issues"
|
|
56
56
|
},
|
|
57
|
-
"homepage": "https://github.com/
|
|
57
|
+
"homepage": "https://github.com/mercurialsolo/counsel-mcp#readme",
|
|
58
58
|
"publishConfig": {
|
|
59
59
|
"access": "public",
|
|
60
60
|
"registry": "https://registry.npmjs.org/"
|