Creating an agent leveraging documentation#
In this example, we're going to crawl a documentation website, store the content in a vector database and leverage it to answer questions about the documentation.
Create the vector database#
We're going to use the doc2vec project to crawl the MCP documentation website and store the content in a SQLite-vec database.
Clone the doc2vec repo:
git clone https://github.com/kagent-dev/doc2vec.git
Install the dependencies:
cd doc2vecnpm install
Set the OPENAI_API_KEY environment variable:
export OPENAI_API_KEY=<your key>
Update the configuration file to crawl the MCP documentation:
cat <<EOF > config.yamlsources:- type: websiteproduct_name: 'mcp'version: 'latest'url: 'https://modelcontextprotocol.io/'max_size: 1048576database_config:type: 'sqlite'params:db_path: './mcp.db'EOF
Launch the process:
npm start
It will take several minutes to complete.
Create an MCP server to use the MCP documentation database#
Now that we have the database, we can create an MCP server to leverage it.
The goal is to deploy it on Kubernetes to allow our agent to use it.
To simplify the process, we're going to store the database in the Docker image.
Let's build and push the Docker image:
cd mcpcp ../mcp.db .docker build -t <your docker repository> .docker push <your docker repository> .
** Important: Dockerfile Modifications Required**
Make sure you add these essential lines to the Dockerfile before building:
# Add this environment variableENV SQLITE_DB_DIR=/data# Create the data directory and copy your databaseRUN mkdir -p /dataCOPY mcp.db /data/mcp.db# Update the ownership to include /dataRUN chown -R kagent:nodejs /app /dataThese changes ensure the MCP server can locate your custom documentation database in the
/datadirectory.
Deploy the MCP server#
Create a Secret for the OpenAI API Key which is going to be used to create the embeddings:
kubectl create secret generic mcp-secrets \--from-literal=OPENAI_API_KEY=<your_openai_api_key> \-n kagent
Create a ConfigMap for the Database Configuration:
kubectl create configmap mcp-config \--from-literal=SQLITE_DB_DIR=/data \--from-literal=PORT=3001 \-n kagent
Create a file named deployment.yaml:
apiVersion: apps/v1kind: Deploymentmetadata:name: mcp-sqlite-vecnamespace: kagentlabels:app: mcp-sqlite-vecspec:replicas: 1selector:matchLabels:app: mcp-sqlite-vectemplate:metadata:labels:app: mcp-sqlite-vecspec:containers:- name: mcp-sqlite-vecimage: <your docker repository>imagePullPolicy: Alwaysports:- containerPort: 3001env:- name: OPENAI_API_KEYvalueFrom:secretKeyRef:name: mcp-secretskey: OPENAI_API_KEY- name: SQLITE_DB_DIRvalueFrom:configMapKeyRef:name: mcp-configkey: SQLITE_DB_DIR- name: PORTvalueFrom:configMapKeyRef:name: mcp-configkey: PORT
Apply it:
kubectl apply -f deployment.yaml
Create a file named service.yaml:
apiVersion: v1kind: Servicemetadata:name: mcp-sqlite-vecnamespace: kagentspec:selector:app: mcp-sqlite-vecports:- port: 3001targetPort: 3001type: ClusterIP
Apply it:
kubectl apply -f service.yaml
Use the MCP server in kagent#
You can configure the MCP server in kagent using either the web UI or YAML manifests.
Option 1: Using the kagent dashboard#

In the kagent UI, click on the Create dropdown menu and select New Tool Server.
Call it sqlite-vec.
Select URL and use http://mcp-sqlite-vec.kagent:3001/mcp.

Click on Add Server.
After refreshing the page, you should see the query-documentation tool being discovered.

Option 2: Using YAML CRDs#
Create a remote-mcpserver.yaml file:
apiVersion: kagent.dev/v1alpha2kind: RemoteMCPServermetadata:name: live-demonamespace: kagentstatus:spec:description: ''protocol: STREAMABLE_HTTPsseReadTimeout: 5m0sterminateOnClose: truetimeout: 5surl: http://mcp-sqlite-vec.kagent:3001/mcp
Apply the ToolServer:
kubectl apply -f toolserver.yaml
Create the MCP agent#
Option 1: Using the kagent dashboard#
Click on the Create dropdown menu and select New Agent.
Use the following information:
- Agent Name: mcp-agent
- Description: The MCP agent is answering questions about MCP, using the MCP documentation
- Agent Instructions: Use your tool to answer any question about the Model Context Protocol (MCP). Use
mcpfor the product andlatestfor the version.
Click on Add Tools.
Select the query-documentation tool.
Option 2: Using YAML CRDs#
Create an agent.yaml file:
# Kagent Agent Configuration# This defines an AI agent that can answer questions about MCP documentationapiVersion: kagent.dev/v1alpha2kind: Agentmetadata:name: sqlite-vecnamespace: kagentspec:declarative:modelConfig: default-model-configstream: truesystemMessage: ' Use your tool to answer any question about the Model Context Protocol (MCP). Use mcp for the product and latest for the version'tools:- mcpServer:apiGroup: kagent.devkind: RemoteMCPServername: live-demotoolNames:- query_documentationtype: McpServerdescription: |The MCP agent is answering questions about MCP, using the MCP documentationtype: Declarative
Apply the Agent:
kubectl apply -f agent.yaml

Congratulations, the agent is ready!
Use the MCP agent#
Click on the agent and ask a question.
For example, How can you build an MCP server using sse?

As you can see, the agent has used the query-documentation tool to answer the question.