@363045841yyt/klinechart-ai-runtime
v0.1.1
Published
AI Native runtime for @363045841yyt/klinechart — MCP tool schemas, controller describe() output, chart state serialization.
Maintainers
Readme
@363045841yyt/klinechart-ai-runtime
MCP (Model Context Protocol) server and AI tool schemas for @363045841yyt/klinechart-core (npm) / @363045841yyt/klinechart (npm).
Optional addon — install only if you need AI agent / MCP control of your charts.
Provides a WebSocket-bridged MCP server that enables AI agents (via MCP Inspector or any MCP client) to control K-line chart operations — zoom, pan, add/remove indicators, change theme, and more.
Installation
pnpm add @363045841yyt/klinechart-ai-runtimeRequires @363045841yyt/klinechart-core as a peer dependency.
Quick Start
Start the MCP server
import { createMcpServer } from '@363045841yyt/klinechart-ai-runtime/mcp-server'
const { start, stop } = createMcpServer({
ws: { port: 8080 },
})
await start()Integrate with KLineChart (Vue example)
<script setup lang="ts">
import KLineChart from '@363045841yyt/klinechart'
import { executeTool } from '@363045841yyt/klinechart-ai-runtime'
const chartRef = ref<InstanceType<typeof KLineChart> | null>(null)
const mcpConfig = {
wsUrl: 'ws://localhost:8080',
autoReconnect: true,
onToolCall: (call) => {
const ctrl = chartRef.value?.getController?.()
if (!ctrl) return { success: false, error: 'Controller not ready' }
return executeTool(ctrl, call)
},
}
</script>
<template>
<KLineChart ref="chartRef" :mcp="mcpConfig" />
</template>Connect from MCP Inspector
cd packages/ai-runtime
pnpm inspectThen call tools like chart.zoomToLevel with { "level": 5 }.
Exports
Main entry (@363045841yyt/klinechart-ai-runtime)
| Export | Description |
|--------|-------------|
| executeTool | Dispatch a tool call to a chart controller |
| ALL_TOOLS | Array of all supported tool schemas |
| TOOL_GROUPS | Grouped tool definitions |
| findTool(name) | Look up a tool schema by name |
| describeVolumeProfileState | Generate VP state summary |
| describeAnchoredVwap | Generate anchored VWAP summary |
| describeFootprintLatestBar | Generate footprint summary |
| describeAlerts | Generate alerts summary |
| serialize / deserialize | Chart state serialization |
| SessionRegistry | WebSocket session manager |
MCP Server (@363045841yyt/klinechart-ai-runtime/mcp-server)
| Export | Description |
|--------|-------------|
| createMcpServer(options) | Create MCP + WebSocket server instance |
Create with MCP (@363045841yyt/klinechart-ai-runtime/create-with-mcp)
Legacy helper — prefer executeTool + mcp prop pattern above.
Architecture
┌─────────────────┐ WebSocket ┌───────────────────┐
│ Browser │◄─────────────────────────►│ MCP Server │
│ │ register / tool:call │ (Node.js) │
│ KLineChart │ tool:result / │ │
│ └─ ChartBridge │ state:update │ ┌─ SessionRegistry│
│ ↓ │ │ └─ WsSessionHandle│
│ └─ onToolCall ─┼───────────────────────────┼──► executeTool │
└─────────────────┘ └────────┬──────────┘
│ stdio
▼
┌────────────────────┐
│ MCP Client │
│ (Inspector / AI) │
└────────────────────┘Available Tools
| Tool | Description |
|------|-------------|
| chart.zoomToLevel | Zoom to a specific level |
| chart.setTheme | Switch between light/dark theme |
| indicators.add | Add an indicator by definition ID |
| indicators.remove | Remove an indicator by instance ID |
| indicators.updateParams | Update indicator parameters |
License
MIT
