> ## Documentation Index
> Fetch the complete documentation index at: https://docs.agentfront.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# FrontMCP Integration

> Use VectoriaDB with FrontMCP for intelligent tool discovery

Use VectoriaDB with [FrontMCP](https://frontmcp.com) for intelligent tool discovery in MCP servers.

## Setup

```ts title="src/mcp/tool-index.ts" theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
import { VectoriaDB, FileStorageAdapter, SerializationUtils, DocumentMetadata } from 'vectoriadb';
import { MCPServer, Tool } from 'frontmcp';

interface ToolDocument extends DocumentMetadata {
  toolName: string;
  owner: string;
  tags: string[];
  risk: 'safe' | 'destructive';
}

// Create VectoriaDB instance
const toolIndex = new VectoriaDB<ToolDocument>({
  storageAdapter: new FileStorageAdapter({
    cacheDir: './.cache/vectoriadb',
    namespace: 'mcp-tools',
  }),
  defaultSimilarityThreshold: 0.4,
});

// Index MCP tools
export async function indexMCPTools(server: MCPServer) {
  await toolIndex.initialize();

  const tools = server.getTools();
  const documents = tools.map((tool: Tool) => ({
    id: tool.name,
    text: `${tool.name}: ${tool.description}`,
    metadata: {
      id: tool.name,
      toolName: tool.name,
      owner: 'mcp',
      tags: tool.tags || [],
      risk: tool.annotations?.destructiveHint ? 'destructive' : 'safe',
    },
  }));

  await toolIndex.addMany(documents);
  await toolIndex.saveToStorage();
}

// Search for relevant tools
export async function findTools(query: string, options?: { filter?: (m: ToolDocument) => boolean }) {
  return toolIndex.search(query, {
    topK: 5,
    threshold: 0.4,
    filter: options?.filter,
  });
}
```

## Usage with FrontMCP Server

```ts title="src/mcp/server.ts" theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
import { MCPServer } from 'frontmcp';
import { indexMCPTools, findTools } from './tool-index';

const server = new MCPServer({
  name: 'my-mcp-server',
});

// Register your tools
server.tool('users:list', 'List all users', async () => { /* ... */ });
server.tool('users:create', 'Create a new user', async () => { /* ... */ });

// Index tools for semantic search
await indexMCPTools(server);

// Use in tool discovery
const relevantTools = await findTools('find user accounts');
console.log('Suggested tools:', relevantTools.map(t => t.metadata.toolName));
```

## Dynamic Tool Discovery

```ts title="src/mcp/discovery.ts" theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
// Add a discovery endpoint
server.tool('discover:tools', 'Find relevant tools for a query', async (params) => {
  const { query, category } = params;

  const tools = await findTools(query, {
    filter: category ? (m) => m.tags.includes(category) : undefined,
  });

  return {
    tools: tools.map(t => ({
      name: t.metadata.toolName,
      score: t.score,
      description: t.text,
    })),
  };
});
```

## Related

<CardGroup cols={3}>
  <Card title="Tool Discovery Guide" icon="wand-magic-sparkles" href="/vectoriadb/guides/use-cases/tool-discovery">
    Complete guide
  </Card>

  <Card title="Enclave" icon="shield" href="/vectoriadb/integrations/enclave">
    Enclave integration
  </Card>

  <Card title="Express" icon="node-js" href="/vectoriadb/integrations/express">
    Express integration
  </Card>
</CardGroup>
