Cover image
Try Now
2025-01-10

CodeMirror extension to hook up a Model Context Provider (MCP)

3 years

Works with Finder

1

Github Watches

2

Github Forks

58

Github Stars

codemirror-mcp

A CodeMirror extension that implements the Model Context Protocol (MCP) for resource mentions and prompt commands.

Features

  • Resource Completion: Autocomplete for @resource mentions
  • Resource Decorations: Visual styling for @resource mentions with click handling
  • Prompt Completion: Autocomplete for /prompt commands
  • Theme Support: Customizable styling

Installation

npm install @marimo-team/codemirror-mcp @modelcontextprotocol/sdk
# or
pnpm add @marimo-team/codemirror-mcp @modelcontextprotocol/sdk

Peer Dependencies

This module requires the following peer dependencies:

  • @codemirror/view
  • @codemirror/state
  • @modelcontextprotocol/sdk

Usage

import { WebSocketClientTransport } from "@modelcontextprotocol/sdk/client/websocket.js";
import { mcpExtension, extractResources } from '@marimo-team/codemirror-mcp';
import { EditorView } from '@codemirror/view';

const transport = new WebSocketClientTransport(new URL('ws://localhost:8080'));

const view = new EditorView({
  extensions: [
    // ... other extensions

    mcpExtension({
      // Required options
      transport: transport,

      // Optional options
      logger: console,
      clientOptions: {
        name: 'your-client',
        version: '1.0.0'
      },
      onResourceClick: (resource) => {
        // Open resource
        // e.g. open in a tab, etc.
      },
    }),

    // Handle submit
    keymap.of([
      {
        key: 'Enter',
        run: () => {
          const resources = extractResources(view);
          const formattedResources = resources
            .map(
              ({ resource }) =>
                `${resource.uri} (${resource.type}): ${resource.description || resource.name}`
            )
            .join('\n');
          const prompt = `${view.state.doc.toString()}\n\nResources:\n${formattedResources}`;
          // ... submit prompt to AI server
          // const response = await generateText(prompt);
        },
      },
    ]),
  ],
  parent: document.querySelector('#editor'),
});

Resources

  • Use @resource-uri syntax to reference resources
  • Resources are visually decorated and clickable
  • Click handling for resource interactions
  • Hover tooltips show resource details
  • Customizable theme

Prompts

  • Use /command syntax for prompt commands
  • Autocomplete for available prompts

Development

# Install dependencies
pnpm install

# Run tests
pnpm test

# Run demo
pnpm dev

License

MIT

相关推荐

  • https://maiplestudio.com
  • Find Exhibitors, Speakers and more

  • Yusuf Emre Yeşilyurt
  • I find academic articles and books for research and literature reviews.

  • https://suefel.com
  • Latest advice and best practices for custom GPT development.

  • Carlos Ferrin
  • Encuentra películas y series en plataformas de streaming.

  • Teach you all the details related to YouTube. Solve all your YouTube-related issues.

  • Emmet Halm
  • Converts Figma frames into front-end code for various mobile frameworks.

  • meiko patton
  • Expertly compares newsletter platforms with a Beehiiv bonus

  • WILLIAM JOEL FOTEPING
  • Friendly music guide for 60s-2000s songs, with links to listen online.

  • Joshua Armstrong
  • Confidential guide on numerology and astrology, based of GG33 Public information

  • https://zenepic.net
  • Embark on a thrilling diplomatic quest across a galaxy on the brink of war. Navigate complex politics and alien cultures to forge peace and avert catastrophe in this immersive interstellar adventure.

  • Elijah Ng Shi Yi
  • Advanced software engineer GPT that excels through nailing the basics.

  • huahuayu
  • A unified API gateway for integrating multiple etherscan-like blockchain explorer APIs with Model Context Protocol (MCP) support for AI assistants.

  • deemkeen
  • control your mbot2 with a power combo: mqtt+mcp+llm

  • zhaoyunxing92
  • 本项目是一个钉钉MCP(Message Connector Protocol)服务,提供了与钉钉企业应用交互的API接口。项目基于Go语言开发,支持员工信息查询和消息发送等功能。

    Reviews

    5 (1)
    Avatar
    user_ngjdmJEX
    2025-04-16

    As a dedicated user of codemirror-mcp by marimo-team, I find it incredibly powerful and user-friendly. It significantly enhances my coding experience with its seamless integration and customizable options. This tool is perfect for developers looking to streamline their workflow in coding projects. Highly recommend checking it out on GitHub!