Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions packages/vscode-ide-companion/src/diff-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,10 @@ export class DiffManager {
// Find and close the tab corresponding to the diff view
for (const tabGroup of vscode.window.tabGroups.all) {
for (const tab of tabGroup.tabs) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
const input = tab.input as {
modified?: vscode.Uri;
original?: vscode.Uri;
};
if (input && input.modified?.toString() === rightDocUri.toString()) {
if (
tab.input instanceof vscode.TabInputTextDiff &&
tab.input.modified.toString() === rightDocUri.toString()
) {
await vscode.window.tabGroups.close(tab);
return;
}
Expand Down
18 changes: 8 additions & 10 deletions packages/vscode-ide-companion/src/ide-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ function sendIdeContextUpdateNotification(
transport.send(notification);
}

function getSessionId(req: Request): string | undefined {
const header = req.headers[MCP_SESSION_ID_HEADER];
return Array.isArray(header) ? header[0] : header;
}

export class IDEServer {
private server: HTTPServer | undefined;
private context: vscode.ExtensionContext | undefined;
Expand Down Expand Up @@ -206,10 +211,7 @@ export class IDEServer {
context.subscriptions.push(onDidChangeDiffSubscription);

app.post('/mcp', async (req: Request, res: Response) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
const sessionId = req.headers[MCP_SESSION_ID_HEADER] as
| string
| undefined;
const sessionId = getSessionId(req);
let transport: StreamableHTTPServerTransport;

if (sessionId && this.transports[sessionId]) {
Expand Down Expand Up @@ -291,10 +293,7 @@ export class IDEServer {
});

const handleSessionRequest = async (req: Request, res: Response) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
const sessionId = req.headers[MCP_SESSION_ID_HEADER] as
| string
| undefined;
const sessionId = getSessionId(req);
if (!sessionId || !this.transports[sessionId]) {
this.log('Invalid or missing session ID');
res.status(400).send('Invalid or missing session ID');
Expand Down Expand Up @@ -339,8 +338,7 @@ export class IDEServer {
});

this.server = app.listen(0, '127.0.0.1', async () => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
const address = (this.server as HTTPServer).address();
const address = this.server?.address();
if (address && typeof address !== 'string') {
this.port = address.port;
this.log(`IDE server listening on http://127.0.0.1:${this.port}`);
Expand Down
Loading