@silkweave/core
v1.6.0
Published
Silkweave Core
Downloads
921
Readme
@silkweave/core
Core library for Silkweave - the TypeScript toolkit for building MCP servers and CLI tools from a single set of Actions.
Install
pnpm add @silkweave/coreWhat's Inside
This package provides the foundational building blocks that all Silkweave adapters depend on:
silkweave()- Fluent builder to wire up adapters and actionscreateAction()- Define transport-agnostic actions with Zod input/output schemas- Adapter types -
Adapter,AdapterGenerator,AdapterFactoryinterfaces for building custom adapters - Context -
SilkweaveContextkey-value store withfork()for per-adapter/per-request isolation - Zod utilities -
unwrap()to recursively unwrap Zod wrapper types
Usage
import { silkweave, createAction } from '@silkweave/core'
import z from 'zod'
const GreetAction = createAction({
name: 'greet',
description: 'Greet someone by name',
input: z.object({
name: z.string().describe('Name to greet')
}),
run: async ({ name }, context) => {
return { message: `Hello, ${name}!` }
}
})
// Wire up with any adapter
await silkweave({ name: 'my-app', description: 'My App', version: '1.0.0' })
.adapter(someAdapter)
.action(GreetAction)
.start()API
silkweave(options): Silkweave
| Option | Type | Description |
|--------|------|-------------|
| name | string | Server/app name |
| description | string | Human-readable description |
| version | string | Semantic version |
Returns a builder with .adapter(), .action(), .actions(), .set(), and .start().
createAction(action): Action
| Field | Type | Description |
|-------|------|-------------|
| name | string | Unique action identifier |
| description | string | Human-readable description |
| input | z.ZodObject | Zod schema for input validation |
| output | z.ZodObject | Optional Zod schema for the return type (used by typegen and Fastify OpenAPI) |
| args | (keyof I)[] | Fields to expose as CLI positional arguments |
| isEnabled | (context) => boolean | Gate action availability per adapter |
| run | (input, context) => Promise<O> | The action implementation |
| toolResult | (response, context) => CallToolResult \| undefined | Custom MCP result formatting (optional) |
Adapter Interfaces
interface Adapter {
context: SilkweaveContext
start(actions: Action[]): Promise<void>
stop(): Promise<void>
}
type AdapterGenerator = (options: SilkweaveOptions, baseContext: SilkweaveContext) => Adapter
type AdapterFactory<T = void> = (options: T) => AdapterGeneratorSee Also
- Silkweave README - Full documentation
@silkweave/mcp- MCP stdio and HTTP adapters@silkweave/fastify- Fastify REST adapter@silkweave/cli- CLI adapter@silkweave/vercel- Vercel serverless adapter@silkweave/typegen- Build-time type generation
