Skip to content

nimwire/schema

This page is generated from the module’s exported API and ## documentation comments.

Lightweight JSON Schema validation for tool boundaries.

A tool argument path mirrored into Mcp-Param-{name}.

McpHeaderBinding = object
name*: string
path*: seq[string]
valueType*: string

View source

proc validateJsonSchema(schema: JsonNode; context = "JSON Schema") {.
raises: [McpError, KeyError, Exception], tags: [RootEffect], forbids: [].}
Name Type Default
schema JsonNode
context inferred "JSON Schema"

View source

proc requireJsonSchema(schema: JsonNode; context = "JSON Schema"): JsonNode {.
raises: [McpError, Exception], tags: [RootEffect], forbids: [].}

Returns: JsonNode.

Name Type Default
schema JsonNode
context inferred "JSON Schema"

View source

Return the valid statically reachable x-mcp-header annotations.

proc mcpHeaderBindings(schema: JsonNode): seq[McpHeaderBinding] {.
raises: [Exception, KeyError, McpError], tags: [RootEffect], forbids: [].}

Returns: seq[McpHeaderBinding].

Name Type Default
schema JsonNode

View source

Evaluate the literal subset used by %* without executing user code. A nil result means that the expression is dynamic and will be checked at registration time instead.

proc mcpLiteralJson(node: NimNode): JsonNode {.raises: [], tags: [], forbids: [].}

Returns: JsonNode.

Name Type Default
node NimNode

View source

proc validateMcpSchemaLiteral(node: NimNode; context: string) {.
raises: [Exception], tags: [RootEffect], forbids: [].}
Name Type Default
node NimNode
context string

View source

proc validateToolName(name: string) {.raises: [McpError], tags: [], forbids: [].}
Name Type Default
name string

View source

proc validateToolPresentation(icons, annotations: JsonNode) {.
raises: [McpError, KeyError], tags: [], forbids: [].}
Name Type Default
icons JsonNode
annotations JsonNode

View source

proc mcpSchemaFromType(n: NimNode): JsonNode {.raises: [KeyError, Exception],
tags: [RootEffect], forbids: [].}

Returns: JsonNode.

Name Type Default
n NimNode

View source

proc mcpJsonArgument(arguments: JsonNode; name: string): JsonNode {.
raises: [KeyError], tags: [], forbids: [].}

Returns: JsonNode.

Name Type Default
arguments JsonNode
name string

View source

Decode typed tool arguments while allowing absent Option properties.

proc mcpJsonDecode[T](value: JsonNode): T

Type parameters: T.

Returns: T.

Name Type Default
value JsonNode

View source

Encode typed results with stable, model-facing enum names.

proc mcpJsonEncode[T](value: T): JsonNode

Type parameters: T.

Returns: JsonNode.

Name Type Default
value T

View source

proc validateJsonValue(schema, value: JsonNode; context = "value") {.
raises: [McpError, Exception, KeyError], tags: [RootEffect], forbids: [].}
Name Type Default
schema JsonNode
value JsonNode
context inferred "value"

View source

Derive a JSON Schema for primitives, objects, enums, containers, tables, options, and nested combinations of those types.

macro mcpJsonSchema(T: typedesc): JsonNode

Type parameters: T:type.

Returns: JsonNode.

Name Type Default
T typedesc

View source