Examples · mcp · 323 of 339
client
A Tin program using an MCP server's tools as typed functions.
tin run examples/mcp/client.tin// A Tin program using an MCP server's tools as typed functions.
//
// tin run examples/mcp/client.tin
//
// `import mcp "command"` starts the server (any MCP stdio server: this one is a tiny
// test server next to the file) and checks each extern against the tool list before
// main runs. Results are checked against the declared types, like every extern.
import mcp "node ../../tests/fixtures/fake-mcp.mjs" {
extern fn add(a: int, b: int): int
extern fn weather(city: string): Weather
extern fn fail(): Result<string, string>
}
type Weather = { city: string, tempC: float, sky: string }
fn main() {
print(add(2, 40))
let w = weather("Oslo")
print("{w.city}: {w.tempC}°C, {w.sky}")
match fail() {
Ok(text) => print("ok: {text}"),
Err(e) => print("the tool failed: {e}"),
}
}