aKode: integrazione della memoria di imeAI (plugin memoria)
- nuovo crate ext/memoria: aggiunge le istruzioni del plugin (instructions.md) come developer policy solo se il plugin memoria è abilitato e il suo server MCP è pronto; nessuna modifica alle istruzioni di base, [features] memories resta spento - pollutes_memory configurabile per server MCP (predefinito true) - project_header per i server HTTP: progetto ricavato dalla cartella della sessione (origin come host/owner/repo, altrimenti la cartella), connessioni separate per progetto - token Bearer dei server MCP anche dal portachiavi di aKode, solo sotto mcp:<server> (mai le chiavi dei provider dei modelli) - tool namespace (MCP, multi-agente) appiattiti in <namespace>__<tool> per i server compatibili OpenAI che accettano solo function tool (llama.cpp, ik_llama.cpp, vLLM li scartavano); capacità del provider tool_namespaces - prove: parsing e propagazione, intestazione del progetto, iniezione solo se attivo e connesso, appiattimento e mappatura delle chiamate, chiavi dei provider mai consegnate ai server MCP Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -6,6 +6,8 @@ use std::collections::HashMap;
|
||||
|
||||
fn stdio_server(command: &str, args: &[&str]) -> McpServerConfig {
|
||||
McpServerConfig {
|
||||
pollutes_memory: true,
|
||||
project_header: None,
|
||||
auth: Default::default(),
|
||||
transport: McpServerTransportConfig::Stdio {
|
||||
command: command.to_string(),
|
||||
|
||||
@@ -322,6 +322,16 @@ pub struct McpServerConfig {
|
||||
/// Per-tool settings keyed by tool name.
|
||||
#[serde(default, skip_serializing_if = "HashMap::is_empty")]
|
||||
pub tools: HashMap<String, McpServerToolConfig>,
|
||||
|
||||
/// When `false`, calls to this server do not mark the thread as polluted for memory
|
||||
/// generation. Defaults to `true`.
|
||||
#[serde(default = "default_pollutes_memory", skip_serializing_if = "is_true")]
|
||||
pub pollutes_memory: bool,
|
||||
|
||||
/// HTTP header that carries the project id derived from the session's working directory
|
||||
/// (git `origin` as `host/owner/repo`, else the repository or folder name).
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub project_header: Option<String>,
|
||||
}
|
||||
|
||||
impl McpServerConfig {
|
||||
@@ -473,6 +483,15 @@ pub struct RawMcpServerConfig {
|
||||
pub _name: Option<String>,
|
||||
#[serde(default)]
|
||||
pub tools: Option<HashMap<String, McpServerToolConfig>>,
|
||||
/// When `false`, calls to this server do not mark the thread as polluted for memory
|
||||
/// generation. Defaults to `true`.
|
||||
#[serde(default)]
|
||||
pub pollutes_memory: Option<bool>,
|
||||
/// HTTP header (streamable HTTP only) that carries the project id derived from the
|
||||
/// session's working directory: git `origin` as `host/owner/repo`, else the repository
|
||||
/// or folder name.
|
||||
#[serde(default)]
|
||||
pub project_header: Option<String>,
|
||||
}
|
||||
|
||||
impl TryFrom<RawMcpServerConfig> for McpServerConfig {
|
||||
@@ -510,6 +529,8 @@ impl TryFrom<RawMcpServerConfig> for McpServerConfig {
|
||||
oauth_resource,
|
||||
_name: _,
|
||||
tools,
|
||||
pollutes_memory,
|
||||
project_header,
|
||||
} = raw;
|
||||
|
||||
let startup_timeout_sec = match (startup_timeout_sec, startup_timeout_ms) {
|
||||
@@ -541,6 +562,7 @@ impl TryFrom<RawMcpServerConfig> for McpServerConfig {
|
||||
throw_if_set("stdio", "oauth", oauth.as_ref())?;
|
||||
throw_if_set("stdio", "oauth_resource", oauth_resource.as_ref())?;
|
||||
throw_if_set("stdio", "auth", auth.as_ref())?;
|
||||
throw_if_set("stdio", "project_header", project_header.as_ref())?;
|
||||
let env_vars = env_vars.unwrap_or_default();
|
||||
for env_var in &env_vars {
|
||||
env_var.validate_source()?;
|
||||
@@ -584,6 +606,17 @@ impl TryFrom<RawMcpServerConfig> for McpServerConfig {
|
||||
return Err("invalid transport".to_string());
|
||||
};
|
||||
|
||||
if let Some(header) = &project_header
|
||||
&& (header.is_empty()
|
||||
|| !header
|
||||
.bytes()
|
||||
.all(|byte| byte.is_ascii_alphanumeric() || byte == b'-' || byte == b'_'))
|
||||
{
|
||||
return Err(format!(
|
||||
"project_header `{header}` is not a valid HTTP header name"
|
||||
));
|
||||
}
|
||||
|
||||
let environment_id =
|
||||
environment_id.unwrap_or_else(|| DEFAULT_MCP_SERVER_ENVIRONMENT_ID.to_string());
|
||||
let auth = auth.unwrap_or_default();
|
||||
@@ -622,6 +655,8 @@ impl TryFrom<RawMcpServerConfig> for McpServerConfig {
|
||||
oauth,
|
||||
oauth_resource,
|
||||
tools: tools.unwrap_or_default(),
|
||||
pollutes_memory: pollutes_memory.unwrap_or_else(default_pollutes_memory),
|
||||
project_header,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -641,6 +676,18 @@ const fn default_enabled() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
const fn default_pollutes_memory() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
#[expect(
|
||||
clippy::trivially_copy_pass_by_ref,
|
||||
reason = "serde skip_serializing_if passes a reference"
|
||||
)]
|
||||
fn is_true(value: &bool) -> bool {
|
||||
*value
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema)]
|
||||
#[serde(untagged, deny_unknown_fields, rename_all = "snake_case")]
|
||||
pub enum McpServerTransportConfig {
|
||||
|
||||
@@ -629,6 +629,8 @@ fn deserialize_ignores_unknown_server_fields() {
|
||||
assert_eq!(
|
||||
cfg,
|
||||
McpServerConfig {
|
||||
pollutes_memory: true,
|
||||
project_header: None,
|
||||
auth: Default::default(),
|
||||
transport: McpServerTransportConfig::Stdio {
|
||||
command: "echo".to_string(),
|
||||
@@ -741,3 +743,63 @@ fn deserialize_rejects_inline_bearer_token_field() {
|
||||
"unexpected error: {err}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pollutes_memory_defaults_to_true_and_can_be_disabled() {
|
||||
let default_cfg: McpServerConfig = toml::from_str(
|
||||
r#"
|
||||
url = "https://example.com/mcp"
|
||||
"#,
|
||||
)
|
||||
.expect("should deserialize http config");
|
||||
assert!(default_cfg.pollutes_memory);
|
||||
assert_eq!(default_cfg.project_header, None);
|
||||
|
||||
let cfg: McpServerConfig = toml::from_str(
|
||||
r#"
|
||||
url = "https://example.com/mcp"
|
||||
pollutes_memory = false
|
||||
project_header = "X-Memoria-Project"
|
||||
"#,
|
||||
)
|
||||
.expect("should deserialize memory-neutral http config");
|
||||
assert!(!cfg.pollutes_memory);
|
||||
assert_eq!(cfg.project_header.as_deref(), Some("X-Memoria-Project"));
|
||||
|
||||
let serialized = serde_json::to_value(&cfg).expect("serialize config");
|
||||
assert_eq!(serialized["pollutes_memory"], serde_json::json!(false));
|
||||
assert_eq!(
|
||||
serialized["project_header"],
|
||||
serde_json::json!("X-Memoria-Project")
|
||||
);
|
||||
let serialized_default = serde_json::to_value(&default_cfg).expect("serialize config");
|
||||
assert!(serialized_default.get("pollutes_memory").is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn project_header_is_rejected_for_stdio_and_invalid_names() {
|
||||
let err = toml::from_str::<McpServerConfig>(
|
||||
r#"
|
||||
command = "echo"
|
||||
project_header = "X-Project"
|
||||
"#,
|
||||
)
|
||||
.expect_err("stdio servers cannot send HTTP headers");
|
||||
assert!(
|
||||
err.to_string()
|
||||
.contains("project_header is not supported for stdio"),
|
||||
"unexpected error: {err}"
|
||||
);
|
||||
|
||||
let err = toml::from_str::<McpServerConfig>(
|
||||
r#"
|
||||
url = "https://example.com/mcp"
|
||||
project_header = "X Project"
|
||||
"#,
|
||||
)
|
||||
.expect_err("header names cannot contain spaces");
|
||||
assert!(
|
||||
err.to_string().contains("not a valid HTTP header name"),
|
||||
"unexpected error: {err}"
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user