Skip to content

wip #226

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

wip #226

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
30 changes: 23 additions & 7 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,18 @@
}

async connect(transport: Transport): Promise<void> {
try {
await this.setupAndConnect(transport);
} catch (error) {
this.emitServerEvent("stop", Date.now() - this.startTime, error as Error);
throw error;
}
}

private async setupAndConnect(transport: Transport): Promise<void> {
this.mcpServer.server.registerCapabilities({ logging: {} });
await this.setServerCallbacks(transport);
this.emitServerEvent("start", Date.now() - this.startTime);

this.registerTools();
this.registerResources();
Expand Down Expand Up @@ -64,20 +75,27 @@
});

await initializeLogger(this.mcpServer, this.userConfig.logPath);
await this.validateConfig();

await this.mcpServer.connect(transport);
}

/**
* Sets up the MCP serve instance by registering capabilities and setting up event listeners.
* @param transport - The transport to use for connecting to the server.
*/
async setServerCallbacks(transport: Transport) {

Check failure on line 87 in src/server.ts

View workflow job for this annotation

GitHub Actions / check-style

Async method 'setServerCallbacks' has no 'await' expression
this.mcpServer.server.oninitialized = () => {
this.session.setAgentRunner(this.mcpServer.server.getClientVersion());
this.session.sessionId = new ObjectId().toString();

logger.info(
LogId.serverInitialized,
"server",
`Server started with transport ${transport.constructor.name} and agent runner ${this.session.agentRunner?.name}`
`Server connected with transport ${transport.constructor.name} and agent runner ${this.session.agentRunner?.name}`
);

this.emitServerEvent("start", Date.now() - this.startTime);
this.emitServerEvent("connect", Date.now() - this.startTime);
};

this.mcpServer.server.onclose = () => {
Expand All @@ -88,9 +106,7 @@
this.mcpServer.server.onerror = (error: Error) => {
const closeTime = Date.now();
this.emitServerEvent("stop", Date.now() - closeTime, error);
};

await this.validateConfig();
};

Check failure on line 109 in src/server.ts

View workflow job for this annotation

GitHub Actions / check-style

Delete `············`
}

async close(): Promise<void> {
Expand All @@ -101,7 +117,7 @@

/**
* Emits a server event
* @param command - The server command (e.g., "start", "stop", "register", "deregister")
* @param command - The server command (e.g., "start", "stop", "connect")
* @param additionalProperties - Additional properties specific to the event
*/
private emitServerEvent(command: ServerCommand, commandDuration: number, error?: Error) {
Expand All @@ -117,7 +133,7 @@
},
};

if (command === "start") {
if (command === "start" || command === "connect") {
event.properties.startup_time_ms = commandDuration;
event.properties.read_only_mode = this.userConfig.readOnly || false;
event.properties.disabled_tools = this.userConfig.disabledTools || [];
Expand Down
2 changes: 1 addition & 1 deletion src/telemetry/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Result type constants for telemetry events
*/
export type TelemetryResult = "success" | "failure";
export type ServerCommand = "start" | "stop";
export type ServerCommand = "start" | "stop" | "connect";
export type TelemetryBoolSet = "true" | "false";

/**
Expand Down
Loading