Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/pinecone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub struct AssistantContext {

#[derive(Debug, Deserialize)]
pub struct AssistantContextResponse {
pub snippets: serde_json::Value,
pub snippets: Vec<serde_json::Value>,
pub usage: serde_json::Value,
}

Expand Down Expand Up @@ -108,7 +108,7 @@ mod tests {
.mock("POST", "/assistant/chat/test-assistant/context")
.with_status(200)
.with_header("content-type", "application/json")
.with_body(r#"{"snippets": [{"text": "This is a test response"}], "usage": {"total_tokens": 100}}"#)
.with_body(r#"{"snippets": [{"text": "snippet 1"}, {"text": "snippet 2"}], "usage": {"total_tokens": 100}}"#)
.create();

let client = PineconeClient::new("test-api-key".to_string(), server.url());
Expand All @@ -119,7 +119,8 @@ mod tests {

mock.assert();
let response = result.unwrap();
assert_eq!(response.snippets[0]["text"], "This is a test response");
assert_eq!(response.snippets[0]["text"], "snippet 1");
assert_eq!(response.snippets[1]["text"], "snippet 2");
}

#[tokio::test]
Expand Down
30 changes: 16 additions & 14 deletions src/router.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::config::Config;
use crate::pinecone::{PineconeClient, PineconeError};
use mcp_server::router::CapabilitiesBuilder;
use mcp_spec::content::Content;
use mcp_spec::handler::{PromptError, ResourceError, ToolError};
use mcp_spec::prompt::Prompt;
use mcp_spec::{protocol::ServerCapabilities, resource::Resource, tool::Tool};
use mcp_server::router::CapabilitiesBuilder;
use serde_json::Value;
use std::future::Future;
use std::pin::Pin;
Expand Down Expand Up @@ -52,21 +52,24 @@ impl PineconeAssistantRouter {
client,
tools: vec![Tool::new(
TOOL_ASSISTANT_CONTEXT.to_string(),
"Retrieve context snippets from a Pinecone assistant knowledge base".to_string(),
"Retrieves relevant document snippets from your Pinecone Assistant knowledge base. \
Returns an array of text snippets from the most relevant documents. \
You can use the 'top_k' parameter to control result count (default: 15). \
Recommended top_k: a few (5-8) for simple/narrow queries, 10-20 for complex/broad topics.".to_string(),
serde_json::json!({
"type": "object",
"properties": {
PARAM_ASSISTANT_NAME: {
"type": "string",
"description": "Name of the Pinecone assistant"
"description": "Name of an existing Pinecone assistant"
},
PARAM_QUERY: {
"type": "string",
"description": "The query to use for generating context."
"description": "The query to retrieve context for."
},
PARAM_TOP_K: {
"type": "integer",
"description": "Number of context snippets to return. Default is 15."
"description": "The number of context snippets to retrieve. Defaults to 15."
}
},
"required": [PARAM_ASSISTANT_NAME, PARAM_QUERY]
Expand Down Expand Up @@ -100,7 +103,11 @@ impl PineconeAssistantRouter {
.await?;

tracing::info!("Successfully received response from Pinecone API");
Ok(vec![Content::text(response.snippets.to_string())])
Ok(response
.snippets
.iter()
.map(|snippet| Content::text(snippet.to_string()))
.collect())
}
}

Expand All @@ -111,14 +118,9 @@ impl mcp_server::Router for PineconeAssistantRouter {

fn instructions(&self) -> String {
format!(
"This server provides tools to interact with Pinecone's Assistant API. \
The {TOOL_ASSISTANT_CONTEXT} tool allows you to retrieve relevant context snippets from given knowledge base assistants. \
Returned value structure: \
An array of relevant document snippets, each containing: \
- content: The text content of the snippet \
- score: A relevance score (float) \
- reference: Source information including document ID and location \
You can tune the number of returned snippets by setting the `top_k` parameter."
"This server connects to an existing Pinecone Assistant,\
a RAG system for retrieving relevant document snippets. \
Use the {TOOL_ASSISTANT_CONTEXT} tool to access contextual information from its knowledge base"
)
}

Expand Down