Skip to content

Commit 76662a0

Browse files
authored
Refactor tools (#25)
2 parents 4f2394b + 977093e commit 76662a0

File tree

6 files changed

+347
-353
lines changed

6 files changed

+347
-353
lines changed

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { withSentry } from "@sentry/cloudflare";
22
import OAuthProvider from "@cloudflare/workers-oauth-provider";
33
import app from "./app";
4-
import SentryMCP from "./mcp";
4+
import SentryMCP from "./mcp/server";
55
import { SCOPES } from "./routes/auth";
66

77
// required for Durable Objects
8-
export { default as SentryMCP } from "./mcp";
8+
export { default as SentryMCP } from "./mcp/server";
99

1010
const oAuthProvider = new OAuthProvider({
1111
apiRoute: "/sse",

src/mcp.ts

Lines changed: 0 additions & 311 deletions
This file was deleted.

src/mcp/schema.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { z } from "zod";
2+
3+
export const ParamOrganizationSlug = z
4+
.string()
5+
.describe("The organization's slug. This will default to the first org you have access to.");
6+
7+
export const ParamTeamSlug = z
8+
.string()
9+
.describe("The team's slug. This will default to the first team you have access to.");
10+
11+
export const ParamIssueShortId = z.string().describe("The Issue ID. e.g. `PROJECT-1Z43`");
12+
13+
export const ParamPlatform = z
14+
.string()
15+
.describe("The platform for the project (e.g., python, javascript, react, etc.)");

src/mcp/server.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { McpAgent } from "agents/mcp";
2+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
3+
import type { Props } from "../types";
4+
import { logError } from "../lib/logging";
5+
import { TOOL_DEFINITIONS, TOOL_HANDLERS } from "./tools";
6+
7+
// Context from the auth process, encrypted & stored in the auth token
8+
// and provided to the DurableMCP as this.props
9+
export default class SentryMCP extends McpAgent<Env, unknown, Props> {
10+
server = new McpServer({
11+
name: "Sentry MCP",
12+
version: "0.1.0",
13+
});
14+
15+
async init() {
16+
for (const tool of TOOL_DEFINITIONS) {
17+
const handler = TOOL_HANDLERS[tool.name];
18+
19+
this.server.tool(tool.name, tool.description, tool.paramsSchema || {}, async (...args) => {
20+
try {
21+
// TODO(dcramer): I'm too dumb to figure this out
22+
// @ts-ignore
23+
const output = await handler(this.props, ...args);
24+
25+
return {
26+
content: [
27+
{
28+
type: "text",
29+
text: output,
30+
},
31+
],
32+
};
33+
} catch (error) {
34+
logError(error);
35+
return {
36+
content: [
37+
{
38+
type: "text",
39+
text: `**Error**\n\nIt looks like there was a problem communicating with the Sentry API:\n\n${
40+
error instanceof Error ? error.message : String(error)
41+
}`,
42+
},
43+
],
44+
isError: true,
45+
};
46+
}
47+
});
48+
}
49+
}
50+
}

0 commit comments

Comments
 (0)