Skip to content

feat: vue-i18n mcp (experimental) #2169

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions docs/.vitepress/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { Client } from '@modelcontextprotocol/sdk/client/index.js'
import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js"
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js'


async function main() {
let client: Client
const baseUrl = 'http://localhost:5173/__mcp'

try {
const transport = new StreamableHTTPClientTransport(new URL(baseUrl))
client = new Client(
{
name: 'vue-i18n-docs-client',
version: '0.0.1'
},
{
capabilities: {
sampling: {}
}
}
)
await client.connect(transport)
console.log('connected to server')
} catch (error) {
console.error('Failed to connect using Streamable HTTP transport:', error)

console.log('Streamable HTTP connection failed, falling back to SSE transport')
client = new Client({
name: 'vue-i18n-docs-sse-client',
version: '0.0.1'
});
const sseTransport = new SSEClientTransport(new URL(`${baseUrl}/sse`))
await client.connect(sseTransport)
console.log('Connected using SSE transport')
}

const version = await client.getServerVersion()
console.log('Server version:', version)

// List tools
const tools = await client.listTools()
console.log('list tools', tools)

// List resources
const resources = await client.listResources()
console.log('list resources', resources)
const contents = await client.readResource({
uri: 'vue-i18n://contents'
})
console.log('read resource', contents)
}

main()
16 changes: 14 additions & 2 deletions docs/.vitepress/config.mts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import type { HeadConfig } from 'vitepress'
import { ViteMcp as mcp } from 'vite-plugin-mcp'
import { defineConfig } from 'vitepress'
import llmstxt from 'vitepress-plugin-llms'
import pkg from '../../package.json' with { type: 'json' }
import mcpServer from './mcp'

import type { HeadConfig } from 'vitepress'

const head: HeadConfig[] = [['link', { rel: 'icon', href: '/vue-i18n-logo.png' }]]

Expand All @@ -15,7 +19,15 @@ export default defineConfig({
markdown: { attrs: { disable: true } },

vite: {
plugins: [llmstxt()]
plugins: [llmstxt(), mcp(
{
mcpServerInfo: {
name: 'Vue I18n MCP Docs',
version: pkg.version
},
mcpServerSetup: mcpServer
}
)]
},

themeConfig: {
Expand Down
31 changes: 31 additions & 0 deletions docs/.vitepress/mcp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import fs from 'node:fs/promises'
import path from 'node:path'

import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
import type { ViteDevServer } from 'vite'
import type { SiteConfig } from 'vitepress'

type Awaitable<T> = T | PromiseLike<T>;

export default function mcp(mcpServer: McpServer, viteServer: ViteDevServer): Awaitable<void | McpServer> {
const vitepress = (viteServer.config as any).vitepress as SiteConfig
console.log('Setting up MCP server for Vue I18n docs...', vitepress.userConfig.themeConfig)
// mcpServer.resource('contents', 'vue-i18n://contents', async (uri) => {
mcpServer.resource('contents', 'vue-i18n://contents', {
uri: 'vue-i18n://contents',
name: 'Vue I18n Contents',
description: 'List of Contents for Vue I18n',
}, async (uri) => {
const filePath = path.resolve(import.meta.dirname, './dist/llms.txt')
const content = await fs.readFile(filePath, 'utf-8')
return {
contents: [
{
uri,
text: content,
}
]
}
})
return mcpServer
}
1 change: 1 addition & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export default [
// ignore globally
{
ignores: [
'tools/mcp/**',
'**/dist/**',
'**/fixtures/**',
'**/coverage/**',
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"docs:dev": "vitepress dev docs",
"docs:serve": "vitepress serve docs",
"docs:setup": "pnpm build:typed && pnpm docs:apigen",
"docs:dev:mcp": "tsx docs/.vitepress/client.ts",
"eslint:inspector": "npx @eslint/config-inspector",
"example:ssr": "cd examples/ssr/vite && pnpm dev",
"fix": "run-p lint:fix format:fix",
Expand Down Expand Up @@ -160,6 +161,9 @@
"typescript-eslint": "^8.4.0",
"vitepress": "1.6.3",
"vitepress-plugin-llms": "^1.1.0",
"vite-plugin-mcp": "^0.2.2",
"@modelcontextprotocol/sdk": "^1.12.0",
"vite": "^6.0.0",
"vitest": "^2.1.5",
"vue": "3.5.13",
"vue-i18n": "workspace:*"
Expand Down
Loading