AI Tools

AI tools let Claude interact with your extension programmatically. When you add tools, Claude can read data, make changes, and help users work with your custom file types.

Why Add AI Tools?

Without tools, Claude can only:

  • Read the raw file content

  • Suggest edits to the raw content

With tools, Claude can:

  • Query structured data ("What columns are in this spreadsheet?")

  • Make targeted changes ("Add a row with these values")

  • Perform complex operations ("Sort by the date column")

  • Understand your data model ("What entities are defined?")

Tool Definition Structure

Tools are defined in your extension's entry point:

// src/index.ts
import type { ExtensionAITool } from '@nimbalyst/extension-sdk';

export const aiTools: ExtensionAITool[] = [
  {
    name: 'my_tool_name',
    description: 'What this tool does - Claude reads this to decide when to use it',
    inputSchema: {
      type: 'object',
      properties: {
        param1: {
          type: 'string',
          description: 'Description of param1',
        },
        param2: {
          type: 'number',
          description: 'Description of param2',
        },
      },
      required: ['param1'],
    },
    handler: async (args, context) => {
      // Implement tool logic
      return { result: 'success' };
    },
  },
];

Registering Tools in the Manifest

Add tools to your manifest.json:

Tool Handler Context

The handler receives a context object with useful information:

Example: Spreadsheet Tools

Here's a complete example for a CSV/spreadsheet editor:

Updating File Content

When a tool needs to modify a file, write through the filesystem service:

Nimbalyst will:

  1. Persist the updated file content

  2. Notify the active editor through file watching

  3. Let the editor reload or reconcile its in-memory state

Tool Naming Conventions

Use a prefix for your tools to avoid conflicts:

Examples:

  • csv.get_schema

  • csv.add_row

  • diagram.add_node

  • datamodel.get_entities

Writing Good Tool Descriptions

Claude uses the description to decide when to use your tool. Be specific:

Good:

Bad:

Error Handling

Return errors as objects, not thrown exceptions:

Input Schema

The inputSchema follows JSON Schema format:

Best Practices

  1. Keep tools focused - One tool, one job

  2. Return structured data - Objects are easier for Claude to work with

  3. Include context in responses - Return relevant metadata

  4. Handle missing files gracefully - Check if activeFilePath exists and read through the filesystem service

  5. Validate inputs - Check required parameters

  6. Use descriptive names - get_column_stats not stats

Testing Tools

Test your tools by asking Claude to use them:

"What columns are in this CSV file?"

Claude should invoke your csv.get_schema tool and report the results.

Example: Data Model Tools

For a more complex example, here are tools for a data modeling extension:

Calling AI Models Directly

Extensions can also call AI chat/completion models directly, without going through Claude. This is useful for summarization, classification, code generation, or any task where the extension itself needs an AI response.

Prerequisites

Your manifest must declare permissions.ai: true.

Listing Available Models

Only models from chat providers the user has enabled and configured are returned (Claude, OpenAI, LM Studio). Agent providers like Claude Code are not included.

Non-Streaming Completion

Streaming Completion

For longer responses where you want to show results incrementally:

Multi-Turn Conversations

Pass multiple messages for conversation context:

Structured Output (JSON Mode)

Use responseFormat to constrain the model's output to valid JSON:

For stricter control, use json_schema to enforce a specific shape:

Key Points

  • Stateless: These calls do not create sessions in the session history. Each call is independent.

  • Model selection: Use listModels() to discover available models, then pass an id to chatCompletion() or chatCompletionStream(). If you omit the model, the first available provider's default is used.

  • Chat providers only: Claude, OpenAI, and LM Studio. Agent providers (Claude Code, Codex) are not available through this API.

  • User configuration: The API respects the user's provider settings and API keys. If a provider is disabled or unconfigured, its models won't appear in listModels().

Next Steps

Last updated