Agents

Tools

A tool list for an agent loop.

tools(target) returns { name, description, inputSchema, execute }[]. target is anything with state and dispatch — an EditorView works. Edits are dispatched with userEvent: 'agent', so they undo like any other change and hosts can recognize them.

import { tools } from 'comark-codemirror/agent'

const list = tools(view)
// MCP: tools/list
const definitions = list.map(({ name, description, inputSchema }) => ({ name, description, inputSchema }))
// tools/call
const result = await list.find(t => t.name === call.name)!.execute(call.arguments)
Tool
readnumbered lines, outline, frontmatter, diagnostics, selection; around limits it to a target
completethe completion context and items at line/column or offset
syntaxthe Markdown cheat sheet from llms()
replace, edit, patch, setTextthe edits above
one per commandtoggleMark, setHeading, insertComponent, setProps, propsToYaml, setFrontmatter, insertFootnote, … each also takes target

Anthropic

const response = await client.messages.create({
  model: 'claude-opus-5-5',
  max_tokens: 2048,
  system: llms(view.state),
  tools: list.map(t => ({ name: t.name, description: t.description, input_schema: t.inputSchema })),
  messages,
})
for (const block of response.content) {
  if (block.type === 'tool_use') await list.find(t => t.name === block.name)!.execute(block.input as Record<string, unknown>)
}

AI SDK

import { jsonSchema, tool } from 'ai'

const aiTools = Object.fromEntries(list.map(t => [t.name, tool({ description: t.description, inputSchema: jsonSchema(t.inputSchema), execute: t.execute })]))
Copyright © 2026