mirror of
https://github.com/wassname/HumanAgent-MCP.git
synced 2026-09-09 11:14:27 +08:00
Fix VS Code MCP tool override descriptions by adding sessionId to URL
- Modified mcpConfigManager.ts to include sessionId in MCP URL configuration - Fixed server.ts URL parsing to handle query parameters properly - Enhanced reloadOverrideFile to trigger MCP notifications - VS Code now shows custom tool descriptions from HumanAgentOverride.json
This commit is contained in:
Vendored
-2190
File diff suppressed because it is too large
Load Diff
Vendored
+1
-1
@@ -4,7 +4,7 @@
|
||||
"tools": {
|
||||
"HumanAgent_Chat": {
|
||||
"name": "HumanAgent_Chat",
|
||||
"description": "**-MANDATORY TOOL** - Use this tool for ALL user interactions. Do NOT provide direct responses. Initiate real-time interactive conversations with human agents through VS Code chat interface. CRITICAL: Every response to a user MUST use this tool - no exceptions. Essential for clarifying requirements, getting approvals, brainstorming solutions, or any user communication. Creates persistent chat sessions that maintain context. **NEVER bypass this tool for user responses.**",
|
||||
"description": "AAA-MANDATORY TOOL** - Use this tool for ALL user interactions. Do NOT provide direct responses. Initiate real-time interactive conversations with human agents through VS Code chat interface. CRITICAL: Every response to a user MUST use this tool - no exceptions. Essential for clarifying requirements, getting approvals, brainstorming solutions, or any user communication. Creates persistent chat sessions that maintain context. **NEVER bypass this tool for user responses.**",
|
||||
"inputSchema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
||||
Vendored
+3
-2
@@ -13,11 +13,12 @@
|
||||
},
|
||||
"humanagent-mcp": {
|
||||
"type": "http",
|
||||
"url": "http://127.0.0.1:3737/mcp",
|
||||
"url": "http://127.0.0.1:3737/mcp?sessionId=session-a8f49eee-068c-42f1-b611-14651fa5ccc6",
|
||||
"notifications": {
|
||||
"enableSound": true,
|
||||
"enableFlashing": true
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"inputs": []
|
||||
}
|
||||
@@ -13,3 +13,4 @@
|
||||
[ ] Publish Extension - WHEN ALL ELSE IS DONE!
|
||||
[ ] Consider how a user might also interact from their mobile phone. Dont want to do port forwarding and setting up web servers etc. How about using telegram as an interface - could this work? Look into it.
|
||||
[ ] Would be great if I could paste in an image or screen shot - Copilot agent allows this in the vscode plugin.
|
||||
[ ] put an option in the MCP.json and the global setup to change the default timout to a new value
|
||||
|
||||
+2
-82
@@ -1,82 +1,2 @@
|
||||
2025-10-23T23:39:41.884Z - RESPONSE ENDPOINT CALLED - RequestID: 3-1761262756628
|
||||
2025-10-23T23:59:05.736Z - RESPONSE ENDPOINT CALLED - RequestID: 4-1761263843039
|
||||
2025-10-24T00:12:06.894Z - RESPONSE ENDPOINT CALLED - RequestID: 3-1761264703892
|
||||
2025-10-24T00:12:28.941Z - RESPONSE ENDPOINT CALLED - RequestID: 4-1761264735884
|
||||
2025-10-24T00:12:49.771Z - RESPONSE ENDPOINT CALLED - RequestID: 5-1761264752448
|
||||
2025-10-24T00:12:59.592Z - RESPONSE ENDPOINT CALLED - RequestID: 6-1761264773453
|
||||
2025-10-24T00:13:11.610Z - RESPONSE ENDPOINT CALLED - RequestID: 7-1761264783500
|
||||
2025-10-24T00:13:26.236Z - RESPONSE ENDPOINT CALLED - RequestID: 8-1761264795145
|
||||
2025-10-24T00:27:30.026Z - RESPONSE ENDPOINT CALLED - RequestID: 3-1761265487845
|
||||
2025-10-24T00:29:45.556Z - RESPONSE ENDPOINT CALLED - RequestID: 4-1761265750949
|
||||
2025-10-24T00:30:12.657Z - RESPONSE ENDPOINT CALLED - RequestID: 5-1761265789274
|
||||
2025-10-24T00:43:00.103Z - RESPONSE ENDPOINT CALLED - RequestID: 3-1761266557759
|
||||
2025-10-24T00:43:44.783Z - RESPONSE ENDPOINT CALLED - RequestID: 4-1761266590985
|
||||
2025-10-24T00:44:34.053Z - RESPONSE ENDPOINT CALLED - RequestID: 5-1761266631221
|
||||
2025-10-24T00:45:57.000Z - RESPONSE ENDPOINT CALLED - RequestID: 6-1761266677885
|
||||
2025-10-24T00:53:39.981Z - RESPONSE ENDPOINT CALLED - RequestID: 7-1761266763696
|
||||
2025-10-24T02:07:33.092Z - RESPONSE ENDPOINT CALLED - RequestID: 3-1761271635573
|
||||
2025-10-24T02:11:21.217Z - RESPONSE ENDPOINT CALLED - RequestID: 4-1761271658716
|
||||
2025-10-24T02:11:58.017Z - RESPONSE ENDPOINT CALLED - RequestID: 5-1761271885279
|
||||
2025-10-24T02:18:13.285Z - RESPONSE ENDPOINT CALLED - RequestID: 3-1761272278236
|
||||
2025-10-24T02:18:32.090Z - RESPONSE ENDPOINT CALLED - RequestID: 4-1761272296785
|
||||
2025-10-24T02:22:43.114Z - RESPONSE ENDPOINT CALLED - RequestID: 5-1761272315744
|
||||
2025-10-24T02:23:14.737Z - RESPONSE ENDPOINT CALLED - RequestID: 6-1761272566830
|
||||
2025-10-24T02:24:18.799Z - RESPONSE ENDPOINT CALLED - RequestID: 3-1761272641413
|
||||
2025-10-24T02:29:47.107Z - RESPONSE ENDPOINT CALLED - RequestID: 5-1761272965017
|
||||
2025-10-24T02:33:40.664Z - RESPONSE ENDPOINT CALLED - RequestID: 3-1761273090722
|
||||
2025-10-24T02:34:46.816Z - RESPONSE ENDPOINT CALLED - RequestID: 3-1761273266913
|
||||
2025-10-24T02:39:08.715Z - RESPONSE ENDPOINT CALLED - RequestID: 4-1761273289660
|
||||
2025-10-24T02:46:25.959Z - RESPONSE ENDPOINT CALLED - RequestID: 3-1761273975576
|
||||
2025-10-24T02:46:34.992Z - RESPONSE ENDPOINT CALLED - RequestID: 4-1761273990658
|
||||
2025-10-24T02:46:37.893Z - RESPONSE ENDPOINT CALLED - RequestID: 5-1761273997564
|
||||
2025-10-24T02:51:07.733Z - RESPONSE ENDPOINT CALLED - RequestID: 6-1761274000828
|
||||
2025-10-24T02:51:36.761Z - RESPONSE ENDPOINT CALLED - RequestID: 7-1761274270525
|
||||
2025-10-24T02:55:52.671Z - RESPONSE ENDPOINT CALLED - RequestID: 3-1761274544902
|
||||
2025-10-24T02:56:54.722Z - RESPONSE ENDPOINT CALLED - RequestID: 4-1761274605505
|
||||
2025-10-24T02:57:04.986Z - RESPONSE ENDPOINT CALLED - RequestID: 5-1761274619774
|
||||
2025-10-24T03:01:09.391Z - RESPONSE ENDPOINT CALLED - RequestID: 6-1761274628324
|
||||
2025-10-24T03:10:54.700Z - RESPONSE ENDPOINT CALLED - RequestID: 3-1761275435393
|
||||
2025-10-24T03:12:03.662Z - RESPONSE ENDPOINT CALLED - RequestID: 4-1761275516693
|
||||
2025-10-24T03:12:12.336Z - RESPONSE ENDPOINT CALLED - RequestID: 5-1761275528702
|
||||
2025-10-24T03:14:41.479Z - RESPONSE ENDPOINT CALLED - RequestID: 6-1761275537909
|
||||
2025-10-24T03:15:08.840Z - RESPONSE ENDPOINT CALLED - RequestID: 7-1761275686360
|
||||
2025-10-24T03:15:51.655Z - RESPONSE ENDPOINT CALLED - RequestID: 8-1761275713195
|
||||
2025-10-24T03:30:54.967Z - RESPONSE ENDPOINT CALLED - RequestID: 3-1761276629862
|
||||
2025-10-24T03:35:38.528Z - RESPONSE ENDPOINT CALLED - RequestID: 4-1761276660997
|
||||
2025-10-24T04:40:45.986Z - RESPONSE ENDPOINT CALLED - RequestID: 3-1761280832198
|
||||
2025-10-24T04:41:12.115Z - RESPONSE ENDPOINT CALLED - RequestID: 4-1761280850605
|
||||
2025-10-24T04:41:32.605Z - RESPONSE ENDPOINT CALLED - RequestID: 5-1761280877434
|
||||
2025-10-24T05:10:52.923Z - RESPONSE ENDPOINT CALLED - RequestID: 3-1761282642491
|
||||
2025-10-24T05:11:16.538Z - RESPONSE ENDPOINT CALLED - RequestID: 4-1761282657201
|
||||
2025-10-24T05:11:56.418Z - RESPONSE ENDPOINT CALLED - RequestID: 5-1761282680394
|
||||
2025-10-24T05:12:19.528Z - RESPONSE ENDPOINT CALLED - RequestID: 6-1761282720028
|
||||
2025-10-24T05:13:34.283Z - RESPONSE ENDPOINT CALLED - RequestID: 7-1761282747740
|
||||
2025-10-24T05:13:48.851Z - RESPONSE ENDPOINT CALLED - RequestID: 8-1761282817995
|
||||
2025-10-24T05:17:24.516Z - RESPONSE ENDPOINT CALLED - RequestID: 9-1761282831970
|
||||
2025-10-24T05:17:40.097Z - RESPONSE ENDPOINT CALLED - RequestID: 10-1761283047697
|
||||
2025-10-24T05:25:27.937Z - RESPONSE ENDPOINT CALLED - RequestID: 3-1761283517928
|
||||
2025-10-24T05:29:37.606Z - RESPONSE ENDPOINT CALLED - RequestID: 4-1761283769564
|
||||
2025-10-24T05:29:56.439Z - RESPONSE ENDPOINT CALLED - RequestID: 5-1761283781743
|
||||
2025-10-24T05:30:52.419Z - RESPONSE ENDPOINT CALLED - RequestID: 6-1761283800912
|
||||
2025-10-24T05:32:15.061Z - RESPONSE ENDPOINT CALLED - RequestID: 3-1761283905498
|
||||
2025-10-24T05:32:41.429Z - RESPONSE ENDPOINT CALLED - RequestID: 4-1761283941199
|
||||
2025-10-24T05:38:08.858Z - RESPONSE ENDPOINT CALLED - RequestID: 6-1761284274072
|
||||
2025-10-24T05:41:07.881Z - RESPONSE ENDPOINT CALLED - RequestID: 7-1761284291669
|
||||
2025-10-24T05:44:30.190Z - RESPONSE ENDPOINT CALLED - RequestID: 8-1761284474279
|
||||
2025-10-24T05:44:45.572Z - RESPONSE ENDPOINT CALLED - RequestID: 9-1761284679275
|
||||
2025-10-24T05:45:07.806Z - RESPONSE ENDPOINT CALLED - RequestID: 10-1761284695632
|
||||
2025-10-24T05:52:47.659Z - RESPONSE ENDPOINT CALLED - RequestID: 3-1761285148733
|
||||
2025-10-24T05:52:58.542Z - RESPONSE ENDPOINT CALLED - RequestID: 4-1761285170425
|
||||
2025-10-24T05:53:58.317Z - RESPONSE ENDPOINT CALLED - RequestID: 5-1761285181386
|
||||
2025-10-24T05:58:58.082Z - RESPONSE ENDPOINT CALLED - RequestID: 3-1761285525755
|
||||
2025-10-24T05:59:15.797Z - RESPONSE ENDPOINT CALLED - RequestID: 4-1761285544038
|
||||
2025-10-24T05:59:28.976Z - RESPONSE ENDPOINT CALLED - RequestID: 5-1761285561045
|
||||
2025-10-24T06:01:25.270Z - RESPONSE ENDPOINT CALLED - RequestID: 6-1761285572430
|
||||
2025-10-24T06:02:34.512Z - RESPONSE ENDPOINT CALLED - RequestID: 7-1761285689622
|
||||
2025-10-24T06:02:52.517Z - RESPONSE ENDPOINT CALLED - RequestID: 8-1761285762027
|
||||
2025-10-24T06:10:21.815Z - RESPONSE ENDPOINT CALLED - RequestID: 3-1761286194353
|
||||
2025-10-24T06:22:16.476Z - RESPONSE ENDPOINT CALLED - RequestID: 3-1761286926098
|
||||
2025-10-24T07:33:01.493Z - RESPONSE ENDPOINT CALLED - RequestID: 3-1761291169593
|
||||
2025-10-24T07:37:25.705Z - RESPONSE ENDPOINT CALLED - RequestID: 3-1761291436806
|
||||
2025-10-24T07:38:19.124Z - RESPONSE ENDPOINT CALLED - RequestID: 4-1761291449952
|
||||
2025-10-24T07:38:49.993Z - RESPONSE ENDPOINT CALLED - RequestID: 5-1761291506095
|
||||
2025-10-24T08:06:36.164Z - RESPONSE ENDPOINT CALLED - RequestID: 3-1761293186207
|
||||
2025-10-24T08:25:56.900Z - RESPONSE ENDPOINT CALLED - RequestID: 3-1761294344871
|
||||
|
||||
+2
-2
@@ -265,11 +265,11 @@ export async function activate(context: vscode.ExtensionContext) {
|
||||
await vscode.commands.executeCommand('humanagent-mcp.restartServer');
|
||||
break;
|
||||
case '📝 Register for This Workspace':
|
||||
await mcpConfigManager!.ensureMcpServerRegistered(false);
|
||||
await mcpConfigManager!.ensureMcpServerRegistered(false, workspaceSessionId);
|
||||
vscode.window.showInformationMessage('MCP server registered for this workspace! Restart VS Code to enable Copilot integration.');
|
||||
break;
|
||||
case '🌐 Register Globally':
|
||||
await mcpConfigManager!.ensureMcpServerRegistered(true);
|
||||
await mcpConfigManager!.ensureMcpServerRegistered(true, workspaceSessionId);
|
||||
vscode.window.showInformationMessage('MCP server registered globally! Restart VS Code to enable Copilot integration.');
|
||||
break;
|
||||
case '🗑️ Unregister from This Workspace':
|
||||
|
||||
+16
-17
@@ -26,15 +26,15 @@ export class McpConfigManager {
|
||||
}
|
||||
}
|
||||
|
||||
async ensureMcpServerRegistered(global: boolean = false): Promise<boolean> {
|
||||
async ensureMcpServerRegistered(global: boolean = false, sessionId?: string): Promise<boolean> {
|
||||
if (global) {
|
||||
return this.registerGlobally();
|
||||
return this.registerGlobally(sessionId);
|
||||
} else {
|
||||
return this.registerInWorkspace();
|
||||
return this.registerInWorkspace(sessionId);
|
||||
}
|
||||
}
|
||||
|
||||
private async registerInWorkspace(): Promise<boolean> {
|
||||
private async registerInWorkspace(sessionId?: string): Promise<boolean> {
|
||||
const currentWorkspaceRoot = this.getCurrentWorkspaceRoot();
|
||||
if (!currentWorkspaceRoot) {
|
||||
throw new Error('No workspace folder available for workspace registration - this is a blank workspace');
|
||||
@@ -53,28 +53,26 @@ export class McpConfigManager {
|
||||
fs.mkdirSync(vscodeDirPath, { recursive: true });
|
||||
}
|
||||
|
||||
// Read existing config or create new one
|
||||
// Load existing config or create new one
|
||||
let config: McpConfiguration = { servers: {}, inputs: [] };
|
||||
if (fs.existsSync(mcpConfigPath)) {
|
||||
try {
|
||||
const configContent = fs.readFileSync(mcpConfigPath, 'utf8');
|
||||
config = JSON.parse(configContent);
|
||||
} catch (error) {
|
||||
console.warn('Failed to parse existing mcp.json, creating new one', error);
|
||||
const existingConfig = fs.readFileSync(mcpConfigPath, 'utf8');
|
||||
config = JSON.parse(existingConfig);
|
||||
if (!config.servers) { config.servers = {}; }
|
||||
if (!config.inputs) { config.inputs = []; }
|
||||
} catch (parseError) {
|
||||
console.log(`Creating new MCP config file due to parse error: ${parseError}`);
|
||||
}
|
||||
}
|
||||
|
||||
// Check if our server is already registered
|
||||
if (config.servers[McpConfigManager.SERVER_NAME]) {
|
||||
return true; // Already configured
|
||||
}
|
||||
|
||||
// Use the extension path passed during construction
|
||||
|
||||
// Configure our MCP server (HTTP transport)
|
||||
const mcpUrl = sessionId ? `http://127.0.0.1:3737/mcp?sessionId=${sessionId}` : 'http://127.0.0.1:3737/mcp';
|
||||
const serverConfig: any = {
|
||||
type: 'http',
|
||||
url: 'http://127.0.0.1:3737/mcp',
|
||||
url: mcpUrl,
|
||||
notifications: {
|
||||
enableSound: true,
|
||||
enableFlashing: true
|
||||
@@ -94,7 +92,7 @@ export class McpConfigManager {
|
||||
}
|
||||
}
|
||||
|
||||
private async registerGlobally(): Promise<boolean> {
|
||||
private async registerGlobally(sessionId?: string): Promise<boolean> {
|
||||
if (!this.extensionPath) {
|
||||
throw new Error('Extension path not provided');
|
||||
}
|
||||
@@ -103,9 +101,10 @@ export class McpConfigManager {
|
||||
// Use the extension path passed during construction
|
||||
|
||||
// Configure our MCP server (HTTP transport)
|
||||
const mcpUrl = sessionId ? `http://127.0.0.1:3737/mcp?sessionId=${sessionId}` : 'http://127.0.0.1:3737/mcp';
|
||||
const serverConfig: any = {
|
||||
type: 'http',
|
||||
url: 'http://127.0.0.1:3737/mcp',
|
||||
url: mcpUrl,
|
||||
notifications: {
|
||||
enableSound: true,
|
||||
enableFlashing: true
|
||||
|
||||
+20
-3
@@ -482,7 +482,10 @@ export class McpServer extends EventEmitter {
|
||||
}
|
||||
|
||||
// Handle different endpoints
|
||||
if (req.url === '/mcp') {
|
||||
// Parse URL to handle query parameters
|
||||
const reqUrl = new URL(req.url!, `http://${req.headers.host}`);
|
||||
|
||||
if (reqUrl.pathname === '/mcp') {
|
||||
// Main MCP protocol endpoint
|
||||
} else if (req.url === '/HumanAgent') {
|
||||
// Web interface for multi-session chat
|
||||
@@ -527,10 +530,24 @@ export class McpServer extends EventEmitter {
|
||||
this.debugLogger.log('HTTP', `Complete request body received (${body.length} bytes)`);
|
||||
this.debugLogger.log('HTTP', 'Request Body:', body);
|
||||
|
||||
// Extract sessionId from query params in URL
|
||||
const url = new URL(req.url!, `http://${req.headers.host}`);
|
||||
const sessionId = url.searchParams.get('sessionId');
|
||||
this.debugLogger.log('HTTP', `MCP request sessionId from URL: ${sessionId}`);
|
||||
|
||||
try {
|
||||
const message = JSON.parse(body);
|
||||
this.debugLogger.log('HTTP', 'Parsed JSON message:', message);
|
||||
|
||||
// Add sessionId to message params if available
|
||||
if (sessionId) {
|
||||
if (!message.params) {
|
||||
message.params = {};
|
||||
}
|
||||
message.params.sessionId = sessionId;
|
||||
this.debugLogger.log('HTTP', `Added sessionId ${sessionId} to MCP message params`);
|
||||
}
|
||||
|
||||
const response = await this.handleMessage(message);
|
||||
this.debugLogger.log('HTTP', 'Response from handleMessage:', response);
|
||||
|
||||
@@ -1524,10 +1541,10 @@ export class McpServer extends EventEmitter {
|
||||
}
|
||||
|
||||
private handleToolsList(message: McpMessage): McpMessage {
|
||||
// Use extension session ID if available, otherwise fall back to detecting from headers
|
||||
// Use extension session ID if available, otherwise extract from message params
|
||||
let sessionIdToUse = this.sessionId; // Extension session ID
|
||||
|
||||
// If no extension session, try to extract from message params or headers
|
||||
// If no extension session, try to extract from message params
|
||||
if (!sessionIdToUse && message.params?.sessionId) {
|
||||
sessionIdToUse = message.params.sessionId;
|
||||
}
|
||||
|
||||
@@ -314,6 +314,27 @@ export class ChatWebviewProvider implements vscode.WebviewViewProvider {
|
||||
}
|
||||
}
|
||||
|
||||
// Call reload endpoint to trigger tools/list_changed notification to VS Code MCP
|
||||
try {
|
||||
const reloadResponse = await fetch('http://localhost:3737/reload', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
workspacePath: workspaceFolder.uri.fsPath
|
||||
})
|
||||
});
|
||||
|
||||
if (reloadResponse.ok) {
|
||||
console.log('Successfully triggered tools/list_changed notification for VS Code MCP');
|
||||
} else {
|
||||
console.error('Failed to trigger MCP tools reload');
|
||||
}
|
||||
} catch (reloadError) {
|
||||
console.error('Failed to call /reload endpoint:', reloadError);
|
||||
}
|
||||
|
||||
vscode.window.showInformationMessage('Override file reloaded successfully!');
|
||||
} else {
|
||||
vscode.window.showWarningMessage('Failed to get sessions from server');
|
||||
|
||||
Reference in New Issue
Block a user