Skip to content

Commit c5d1102

Browse files
committed
civet syntax sugar
1 parent 5f97aaf commit c5d1102

File tree

3 files changed

+57
-43
lines changed

3 files changed

+57
-43
lines changed

build.civet

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ targets :=
1414
outputDir := './dist'
1515

1616
// Transpile all Civet source files to JS
17-
await Promise.all
17+
await.all
1818
. $`civet --js -c src/*.civet -o ./dist/.js`
1919
. $`civet --js -c src/tools/*.civet -o ./dist/tools/.js`
2020

@@ -24,37 +24,36 @@ unless fs.existsSync outputDir {
2424
}
2525

2626
// Build the binary for each target
27-
await Promise.all targets.map (target) -> {
28-
console.info `Building for ${target}`
29-
30-
// Remove the `bun-` prefix from the output filename
31-
suffix := target.replace 'bun-', ''
32-
outfile := `${outputDir}/bitbucket-mcp-server-${suffix}`
33-
34-
// Build the binary
35-
try {
36-
await $`bun build \
37-
--compile \
38-
--minify \
39-
--sourcemap \
40-
--target=${target} \
41-
./dist/index.js \
42-
--outfile ${outfile}`
43-
44-
outputFileName := outfile.includes('windows') ? `${outfile}.exe` : outfile
45-
46-
// Create a tarball of the binary
47-
await tar.create {
48-
+gzip
49-
file: `${outfile}.tar.gz`
50-
}, [outputFileName]
51-
52-
// Remove the binary
53-
fs.unlinkSync outputFileName
54-
55-
console.info `Built for ${target}`
56-
} catch error {
57-
console.error `Error building for ${target}: ${error}`
58-
exit 1
59-
}
60-
}
27+
await.all
28+
for target of targets
29+
console.info `Building for ${target}`
30+
31+
// Remove the `bun-` prefix from the output filename
32+
suffix := target.replace 'bun-', ''
33+
outfile := `${outputDir}/bitbucket-mcp-server-${suffix}`
34+
35+
// Build the binary
36+
try
37+
await $`bun build \
38+
--compile \
39+
--minify \
40+
--sourcemap \
41+
--target=${target} \
42+
./dist/index.js \
43+
--outfile ${outfile}`
44+
45+
outputFileName := if outfile.includes 'windows' then `${outfile}.exe` else outfile
46+
47+
// Create a tarball of the binary
48+
await tar.create {
49+
+gzip
50+
file: `${outfile}.tar.gz`
51+
}, [outputFileName]
52+
53+
// Remove the binary
54+
fs.unlinkSync outputFileName
55+
56+
console.info `Built for ${target}`
57+
catch error
58+
console.error `Error building for ${target}: ${error}`
59+
exit 1

src/tool-declaration.civet

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ type { RequestHandlerExtra } from @modelcontextprotocol/sdk/shared/protocol.js
66
{ IS_DEV } from ./const.civet
77

88
// Translates the input/output schema to a basic object type
9-
// Apparently Zod didn't have this feature
9+
// Apparently Zod didn't have this feature (maybe it's skill issue...?)
1010
// Maybe I should just use the `zod-to-json-schema` package? Not sure...
11-
export TInferedSchema<T> ::= [K in keyof T]: T[K] < ZodType ? z.infer<T[K]> : never
11+
export TInferedSchema<T> ::= [K in keyof T]: if T[K] < ZodType then z.infer<T[K]> else never
1212
export TSerializable<T> ::= [K in keyof T]: Primitive | TSerializable<T[K]> | TSerializable<T[K]>[]
1313

1414
export ToolDeclarationConfig ::= {
15-
inputSchema: ZodRawShape < infer TInputSchema ? TInputSchema : never
16-
outputSchema?: ZodRawShape < infer TOutputSchema ? TOutputSchema : never
15+
inputSchema: if ZodRawShape < infer TInputSchema then TInputSchema else never
16+
outputSchema?: if ZodRawShape < infer TOutputSchema then TOutputSchema else never
1717
annotations?: ToolAnnotations
1818
title: string
1919
description: string
@@ -22,7 +22,7 @@ export ToolDeclarationConfig ::= {
2222
export ToolDeclarationRunCallback<TConfig < ToolDeclarationConfig = ToolDeclarationConfig, TConstructor < new (...args: any[]) => any = new () => any> ::=
2323
(
2424
@: ToolDeclaration<TConfig, TConstructor> & InstanceType<TConstructor>,
25-
args: TInferedSchema<TConfig["inputSchema"] < infer TInputSchema ? TInputSchema : never>,
25+
args: TInferedSchema<if TConfig["inputSchema"] < infer TInputSchema then TInputSchema else never>,
2626
extra: RequestHandlerExtra<ServerRequest, ServerNotification>
2727
) -> Promise<
2828
TSerializable<TInferedSchema<TConfig["outputSchema"]>> | TSerializable<TInferedSchema<TConfig["outputSchema"]>>[] | null
@@ -44,7 +44,7 @@ export class ToolDeclaration<TConfig < ToolDeclarationConfig = ToolDeclarationCo
4444

4545
@(args: ToolDeclarationArgs<TConfig, TConstructor>) {
4646
@config = args.config
47-
@run = args.run.bind(@ as any)
47+
@run = args.run.bind @ as InstanceType<TConstructor>
4848
@name = args.name
4949
}
5050
}
@@ -105,8 +105,7 @@ export registerTools := <TConfig < ToolDeclarationConfig, T < ToolDeclaration<TC
105105
member.name,
106106
member.config,
107107
// Wrap the run call in a try/catch and return the result in the MCP format
108-
// @ts-expect-error -- The types are all right here, but the SDK won't know that a `Promise` of the
109-
// `ToolCallback` is a valid `ToolCallback` (because promises are flattened)
108+
// @ts-expect-error FIXME
110109
safeActionCallToOutput member
111110
)
112111
}

tmp/test.civet

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
element := <T < Symbol>({ description: tag }: T) -> (...content: string[]) ->
2+
`<${tag}>${content.join ""}</${tag}>`
3+
4+
div := element :div
5+
html := element :html
6+
body := element :body
7+
head := element :head
8+
title := element :title
9+
p := element :p
10+
11+
(html
12+
(head (title "Hello"))
13+
(body
14+
(div
15+
(p "Hello")
16+
(p "World"))))

0 commit comments

Comments
 (0)