ui: show tool number (#2071)
This commit is contained in:
@@ -18,7 +18,8 @@ use mcp_core::tool::{Tool, ToolAnnotations};
|
||||
super::routes::config_management::remove_extension,
|
||||
super::routes::config_management::get_extensions,
|
||||
super::routes::config_management::read_all_config,
|
||||
super::routes::config_management::providers
|
||||
super::routes::config_management::providers,
|
||||
super::routes::agent::get_tools,
|
||||
),
|
||||
components(schemas(
|
||||
super::routes::config_management::UpsertConfigQuery,
|
||||
|
||||
@@ -7,6 +7,7 @@ use axum::{
|
||||
};
|
||||
use goose::config::Config;
|
||||
use goose::{agents::AgentFactory, model::ModelConfig, providers};
|
||||
use mcp_core::Tool;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashMap;
|
||||
use std::env;
|
||||
@@ -163,11 +164,45 @@ async fn list_providers() -> Json<Vec<ProviderList>> {
|
||||
Json(response)
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
get,
|
||||
path = "/agent/tools",
|
||||
responses(
|
||||
(status = 200, description = "Tools retrieved successfully", body = Vec<Tool>),
|
||||
(status = 401, description = "Unauthorized - invalid secret key"),
|
||||
(status = 424, description = "Agent not initialized"),
|
||||
(status = 500, description = "Internal server error")
|
||||
)
|
||||
)]
|
||||
async fn get_tools(
|
||||
State(state): State<AppState>,
|
||||
headers: HeaderMap,
|
||||
) -> Result<Json<Vec<Tool>>, StatusCode> {
|
||||
let secret_key = headers
|
||||
.get("X-Secret-Key")
|
||||
.and_then(|value| value.to_str().ok())
|
||||
.ok_or(StatusCode::UNAUTHORIZED)?;
|
||||
|
||||
if secret_key != state.secret_key {
|
||||
return Err(StatusCode::UNAUTHORIZED);
|
||||
}
|
||||
|
||||
let mut agent = state.agent.write().await;
|
||||
let agent = agent.as_mut().ok_or(StatusCode::PRECONDITION_REQUIRED)?;
|
||||
|
||||
// Since list_tools() now returns Vec<Tool> directly, not a Result
|
||||
let tools = agent.list_tools().await;
|
||||
|
||||
// Return the tools directly
|
||||
Ok(Json(tools))
|
||||
}
|
||||
|
||||
pub fn routes(state: AppState) -> Router {
|
||||
Router::new()
|
||||
.route("/agent/versions", get(get_versions))
|
||||
.route("/agent/providers", get(list_providers))
|
||||
.route("/agent/prompt", post(extend_prompt))
|
||||
.route("/agent/tools", get(get_tools))
|
||||
.route("/agent", post(create_agent))
|
||||
.with_state(state)
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ use super::extension::{ExtensionConfig, ExtensionResult};
|
||||
use crate::providers::base::Provider;
|
||||
use crate::session;
|
||||
use crate::{message::Message, permission::PermissionConfirmation};
|
||||
use mcp_core::{prompt::Prompt, protocol::GetPromptResult, Content, ToolResult};
|
||||
use mcp_core::{prompt::Prompt, protocol::GetPromptResult, Content, Tool, ToolResult};
|
||||
|
||||
/// Session configuration for an agent
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
@@ -43,6 +43,9 @@ pub trait Agent: Send + Sync {
|
||||
// TODO this needs to also include status so we can tell if extensions are dropped
|
||||
async fn list_extensions(&self) -> Vec<String>;
|
||||
|
||||
/// List the tools this agent has access to
|
||||
async fn list_tools(&self) -> Vec<Tool>;
|
||||
|
||||
/// Pass through a JSON-RPC request to a specific extension
|
||||
async fn passthrough(&self, extension: &str, request: Value) -> ExtensionResult<Value>;
|
||||
|
||||
|
||||
@@ -9,5 +9,5 @@ mod types;
|
||||
|
||||
pub use agent::{Agent, SessionConfig};
|
||||
pub use capabilities::Capabilities;
|
||||
pub use extension::ExtensionConfig;
|
||||
pub use extension::{ExtensionConfig, ExtensionResult};
|
||||
pub use factory::{register_agent, AgentFactory};
|
||||
|
||||
@@ -53,6 +53,11 @@ impl Agent for ReferenceAgent {
|
||||
capabilities.add_extension(extension).await
|
||||
}
|
||||
|
||||
async fn list_tools(&self) -> Vec<Tool> {
|
||||
let mut capabilities = self.capabilities.lock().await;
|
||||
capabilities.get_prefixed_tools().await.unwrap_or_default()
|
||||
}
|
||||
|
||||
async fn remove_extension(&mut self, name: &str) {
|
||||
let mut capabilities = self.capabilities.lock().await;
|
||||
capabilities
|
||||
|
||||
@@ -139,6 +139,11 @@ impl Agent for SummarizeAgent {
|
||||
capabilities.add_extension(extension).await
|
||||
}
|
||||
|
||||
async fn list_tools(&self) -> Vec<Tool> {
|
||||
let mut capabilities = self.capabilities.lock().await;
|
||||
capabilities.get_prefixed_tools().await.unwrap_or_default()
|
||||
}
|
||||
|
||||
async fn remove_extension(&mut self, name: &str) {
|
||||
let mut capabilities = self.capabilities.lock().await;
|
||||
capabilities
|
||||
|
||||
@@ -178,6 +178,11 @@ impl Agent for TruncateAgent {
|
||||
capabilities.add_extension(extension).await
|
||||
}
|
||||
|
||||
async fn list_tools(&self) -> Vec<Tool> {
|
||||
let mut capabilities = self.capabilities.lock().await;
|
||||
capabilities.get_prefixed_tools().await.unwrap_or_default()
|
||||
}
|
||||
|
||||
async fn remove_extension(&mut self, name: &str) {
|
||||
let mut capabilities = self.capabilities.lock().await;
|
||||
capabilities
|
||||
|
||||
Reference in New Issue
Block a user