Skip to content

Commit 8c60866

Browse files
committed
fix dependencies import bug
1 parent 515bafe commit 8c60866

File tree

5 files changed

+45
-40
lines changed

5 files changed

+45
-40
lines changed

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
"main": "src/index.civet",
66
"license": "MIT",
77
"scripts": {
8-
"dev": "bun run --watch src/index.civet",
9-
"inspect": "mcp-inspector bun src/index.civet",
8+
"dev": "NODE_ENV=development bun run --watch src/index.civet",
9+
"inspect": "NODE_ENV=development mcp-inspector bun src/index.civet",
1010
"build": "bun run build.civet",
1111
"start": "./dist/bitbucket-mcp-server"
1212
},
1313
"dependencies": {
1414
"@modelcontextprotocol/sdk": "latest",
1515
"bitbucket": "latest",
16-
"pino": "^9.7.0",
17-
"pino-pretty": "^13.0.0",
16+
"pino": "latest",
17+
"pino-pretty": "latest",
1818
"zod": "latest"
1919
},
2020
"devDependencies": {

src/index.civet

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{ McpServer } from @modelcontextprotocol/sdk/server/mcp.js
22
{ StdioServerTransport } from @modelcontextprotocol/sdk/server/stdio.js
33

4+
* as tools from ./tools/index.civet
5+
46
{ registerTools } from ./tool-declaration.civet
57
{ logger } from ./logger.civet
68

@@ -13,7 +15,7 @@ main := -> {
1315
description: "Bitbucket MCP server",
1416
}
1517
// Register the available tools
16-
|> registerTools
18+
|> registerTools tools
1719
|> await
1820

1921
// Create a transport to listen for messages on stdin and send messages on stdout

src/logger.civet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
pino from pino
22

3-
{ NODE_ENV = "development" } := process.env
3+
{ NODE_ENV } := process.env
44

55
export logger := pino {
66
...(if NODE_ENV is "development" then {

src/tool-declaration.civet

Lines changed: 23 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
{ Glob } from bun
2-
path from node:path
3-
41
{ z, type ZodType, type ZodRawShape, type Primitive } from zod
52
type { ToolAnnotations, ServerRequest, ServerNotification } from @modelcontextprotocol/sdk/types.js
63
type { McpServer } from @modelcontextprotocol/sdk/server/mcp.js
@@ -17,15 +14,19 @@ export TSerializable<T> ::= {
1714
}
1815

1916
export ToolDeclarationConfig ::= {
20-
title?: string
21-
description?: string
22-
inputSchema?: ZodRawShape extends infer TInputSchema ? TInputSchema : never
17+
title: string
18+
description: string
19+
inputSchema: ZodRawShape extends infer TInputSchema ? TInputSchema : never
2320
outputSchema?: ZodRawShape extends infer TOutputSchema ? TOutputSchema : never
2421
annotations?: ToolAnnotations
2522
}
2623

2724
export ToolDeclarationRunCallback<TConfig extends ToolDeclarationConfig = ToolDeclarationConfig, TConstructor extends new (...args: any[]) => any = new () => any> ::=
28-
(@: ToolDeclaration<TConfig, TConstructor> & InstanceType<TConstructor>, args: TInferedSchema<TConfig["inputSchema"]>, extra: RequestHandlerExtra<ServerRequest, ServerNotification>) -> Promise<
25+
(
26+
@: ToolDeclaration<TConfig, TConstructor> & InstanceType<TConstructor>,
27+
args: TInferedSchema<TConfig["inputSchema"] extends infer TInputSchema ? TInputSchema : never>,
28+
extra: RequestHandlerExtra<ServerRequest, ServerNotification>
29+
) -> Promise<
2930
TSerializable<TInferedSchema<TConfig["outputSchema"]>> | TSerializable<TInferedSchema<TConfig["outputSchema"]>>[] | null
3031
>
3132

@@ -63,36 +64,24 @@ safeActionCallToOutput := <T extends ToolDeclaration>(member: T) ->
6364

6465
// All tools are loaded via a glob scan, so we can just iterate over the files and import them
6566
// This means to create new tools you just need to create a new file in `src/tools`
66-
export registerTools := (server: McpServer) -> {
67-
// Prepare to register tools
68-
{ dirname } := import.meta
69-
civetGlob := new Glob "**/*.civet"
70-
toolsPath := path.join dirname, 'tools'
71-
67+
export registerTools := <TConfig extends ToolDeclarationConfig, T extends ToolDeclaration<TConfig>>(tools: Record<string, T>) -> (server: McpServer) -> {
7268
// Register tools based on the glob pattern
73-
for await file of civetGlob.scan toolsPath {
74-
// Import the tool declaration module file
75-
absoluteToolPath := path.join toolsPath, file
76-
toolDeclarationModule := await import absoluteToolPath
77-
toolDeclarationModuleExportedMembers := Object.values toolDeclarationModule
78-
69+
for await member of Object.values tools {
7970
// For each exported member, if it's a tool declaration, register it with the server
80-
for member of toolDeclarationModuleExportedMembers {
81-
// Filter out exports that aren't tool declarations
82-
unless member instanceof ToolDeclaration {
83-
continue
84-
}
85-
86-
// Register the tool with the server
87-
server.registerTool(
88-
member.name,
89-
member.config,
90-
// Wrap the run call in a try/catch and return the result in the MCP format
91-
// @ts-expect-error -- The types are all right here, but the SDK won't know that a `Promise` of the
92-
// `ToolCallback` is a valid `ToolCallback` (because promises are flattened)
93-
safeActionCallToOutput member
94-
)
71+
// Filter out exports that aren't tool declarations
72+
unless member instanceof ToolDeclaration {
73+
continue
9574
}
75+
76+
// Register the tool with the server
77+
server.registerTool(
78+
member.name,
79+
member.config,
80+
// Wrap the run call in a try/catch and return the result in the MCP format
81+
// @ts-expect-error -- The types are all right here, but the SDK won't know that a `Promise` of the
82+
// `ToolCallback` is a valid `ToolCallback` (because promises are flattened)
83+
safeActionCallToOutput member
84+
)
9685
}
9786

9887
// Return the server to allow for chaining

src/tools/index.civet

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export * from ./get-pull-request-comment.civet
2+
export * from ./get-pull-request-diff.civet
3+
export * from ./get-pull-request-task.civet
4+
export * from ./get-pull-request.civet
5+
export * from ./get-repositories.civet
6+
export * from ./get-repository-commit.civet
7+
export * from ./get-repository-diff.civet
8+
export * from ./get-repository.civet
9+
export * from ./get-snippet-raw-files.civet
10+
export * from ./get-workspaces.civet
11+
export * from ./list-commits.civet
12+
export * from ./list-pull-request-comments.civet
13+
export * from ./list-pull-requests.civet
14+
export * from ./list-refs.civet

0 commit comments

Comments
 (0)