mirror of
https://github.com/instructkr/claw-code.git
synced 2026-04-08 00:54:49 +08:00
feat: b5-max-token-plugin — batch 5 upstream parity
This commit is contained in:
@@ -46,14 +46,14 @@ use runtime::{
|
||||
load_oauth_credentials, load_system_prompt, parse_oauth_callback_request_target,
|
||||
pricing_for_model, resolve_sandbox_status, save_oauth_credentials, ApiClient, ApiRequest,
|
||||
AssistantEvent, CompactionConfig, ConfigLoader, ConfigSource, ContentBlock,
|
||||
ConversationMessage, ConversationRuntime, McpServerManager, McpTool, MessageRole, ModelPricing,
|
||||
OAuthAuthorizationRequest, OAuthConfig, OAuthTokenExchangeRequest, PermissionMode,
|
||||
PermissionPolicy, ProjectContext, PromptCacheEvent, ResolvedPermissionMode, RuntimeError,
|
||||
Session, TokenUsage, ToolError, ToolExecutor, UsageTracker,
|
||||
ConversationMessage, ConversationRuntime, McpServer, McpServerManager, McpServerSpec, McpTool,
|
||||
MessageRole, ModelPricing, OAuthAuthorizationRequest, OAuthConfig, OAuthTokenExchangeRequest,
|
||||
PermissionMode, PermissionPolicy, ProjectContext, PromptCacheEvent, ResolvedPermissionMode,
|
||||
RuntimeError, Session, TokenUsage, ToolError, ToolExecutor, UsageTracker,
|
||||
};
|
||||
use serde::Deserialize;
|
||||
use serde_json::{json, Map, Value};
|
||||
use tools::{GlobalToolRegistry, RuntimeToolDefinition, ToolSearchOutput};
|
||||
use tools::{execute_tool, mvp_tool_specs, GlobalToolRegistry, RuntimeToolDefinition, ToolSearchOutput};
|
||||
|
||||
const DEFAULT_MODEL: &str = "claude-opus-4-6";
|
||||
fn max_tokens_for_model(model: &str) -> u32 {
|
||||
@@ -1161,6 +1161,41 @@ fn run_doctor(output_format: CliOutputFormat) -> Result<(), Box<dyn std::error::
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Starts a minimal Model Context Protocol server that exposes claw's
|
||||
/// built-in tools over stdio.
|
||||
///
|
||||
/// Tool descriptors come from [`tools::mvp_tool_specs`] and calls are
|
||||
/// dispatched through [`tools::execute_tool`], so this server exposes exactly
|
||||
/// the same surface the in-process agent loop uses.
|
||||
fn run_mcp_serve() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let tools = mvp_tool_specs()
|
||||
.into_iter()
|
||||
.map(|spec| McpTool {
|
||||
name: spec.name.to_string(),
|
||||
description: Some(spec.description.to_string()),
|
||||
input_schema: Some(spec.input_schema),
|
||||
annotations: None,
|
||||
meta: None,
|
||||
})
|
||||
.collect();
|
||||
|
||||
let spec = McpServerSpec {
|
||||
server_name: "claw".to_string(),
|
||||
server_version: VERSION.to_string(),
|
||||
tools,
|
||||
tool_handler: Box::new(execute_tool),
|
||||
};
|
||||
|
||||
let runtime = tokio::runtime::Builder::new_current_thread()
|
||||
.enable_all()
|
||||
.build()?;
|
||||
runtime.block_on(async move {
|
||||
let mut server = McpServer::new(spec);
|
||||
server.run().await
|
||||
})?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_lines)]
|
||||
fn check_auth_health() -> DiagnosticCheck {
|
||||
let api_key_present = env::var("ANTHROPIC_API_KEY")
|
||||
@@ -3717,6 +3752,12 @@ impl LiveCli {
|
||||
args: Option<&str>,
|
||||
output_format: CliOutputFormat,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
// `claw mcp serve` starts a stdio MCP server exposing claw's built-in
|
||||
// tools. All other `mcp` subcommands fall through to the existing
|
||||
// configured-server reporter (`list`, `status`, ...).
|
||||
if matches!(args.map(str::trim), Some("serve")) {
|
||||
return run_mcp_serve();
|
||||
}
|
||||
let cwd = env::current_dir()?;
|
||||
match output_format {
|
||||
CliOutputFormat::Text => println!("{}", handle_mcp_slash_command(args, &cwd)?),
|
||||
|
||||
Reference in New Issue
Block a user