obsidian-mcp: 初次落地 Obsidian Vault MCP Server (.NET 10, read+write)
把 Obsidian vault 通过 MCP 暴露给 Claude.ai,OAuth 走 nas-auth。 设计文档见 vault Coding/obsidian-mcp/obsidian-mcp 设计.md。 代码层落地参考 vault Coding/obsidian-mcp/MCP 实现指南.md。 V1+V2 同时实现(用户要求跳过分阶段直接全部): 读 Tools(需 scope=read:obsidian): - list_vault_tree(一次性 vault 地图,限制深度) - list_files / read_file(含 offset/limit 大文件分页) - search(子串匹配 + glob 过滤,最多 50 hits) - get_metadata(size / modified_at / has_frontmatter) 写 Tools(需 scope=write:obsidian): - write_file / append_file - 多重门禁:scope 校验 + 路径黑名单 + 写入白名单 + 永禁文件 - 永禁写:任意目录的 AGENTS.md / PROFILE.md / README.md / CLAUDE.md / 01-Secret/** - 白名单:02-ShengquGames/logs/ + Coding/ + NAS/NAS 待办清单.md - 写入审计日志按天 rotate(JSON line) 安全: - VaultPathResolver chroot:path traversal + symlink 双拒绝 - JwtBearer (HS256, Current+Previous fallback, MapInboundClaims=false) - aud=obsidian, iss=https://auth.zhengchentao.win - 黑名单:01-Secret / .obsidian / .trash / .git 技术栈: - .NET 10 + ModelContextProtocol SDK 1.0 - Streamable HTTP transport (POST /mcp) - JwtBearer 10.0 + IdentityModel.Tokens 8.x 部署: - Dockerfile multi-stage,runtime 装 ripgrep(V3 备用),non-root user - .gitea/workflows/build-image.yml:build + deploy 双 job,buildkit v0.13.2 - 容器内 :8080,宿主端口 9090 - 子域名 obs.zhengchentao.win - vault 挂载 /volume1/docker/webdav/data/Zhengchen:/vault:rw(V2 写入需要 rw) 测试:35/35 单测过(VaultPathResolver path traversal/blacklist/symlink + VaultWriteGuard whitelist/forbidden) Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
namespace ObsidianMcp.Config;
|
||||
|
||||
/// <summary>
|
||||
/// JWT 验签配置。
|
||||
/// 环境变量:Jwt__Issuer, Jwt__Audience, Jwt__SigningKey__Current, Jwt__SigningKey__Previous
|
||||
/// </summary>
|
||||
public class JwtOptions
|
||||
{
|
||||
public const string Section = "Jwt";
|
||||
|
||||
/// <summary>期望的 iss claim,生产:https://auth.zhengchentao.win</summary>
|
||||
public string Issuer { get; set; } = "https://auth.zhengchentao.win";
|
||||
|
||||
/// <summary>期望的 aud claim,生产:obsidian</summary>
|
||||
public string Audience { get; set; } = "obsidian";
|
||||
|
||||
public SigningKeyPair SigningKey { get; set; } = new();
|
||||
|
||||
public class SigningKeyPair
|
||||
{
|
||||
/// <summary>当前签名密钥(HS256 对称密钥),env: Jwt__SigningKey__Current</summary>
|
||||
public string Current { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>上一轮密钥,密钥轮换过渡期用,env: Jwt__SigningKey__Previous(可为空)</summary>
|
||||
public string? Previous { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
namespace ObsidianMcp.Config;
|
||||
|
||||
/// <summary>
|
||||
/// /.well-known/oauth-authorization-server 返回的元数据配置。
|
||||
/// 环境变量前缀 Mcp__OAuthDiscovery__,例如 Mcp__OAuthDiscovery__Issuer=...
|
||||
/// </summary>
|
||||
public class McpDiscoveryOptions
|
||||
{
|
||||
public const string Section = "Mcp:OAuthDiscovery";
|
||||
|
||||
public string Issuer { get; set; } = "https://auth.zhengchentao.win";
|
||||
public string AuthorizationEndpoint { get; set; } = "https://auth.zhengchentao.win/authorize";
|
||||
public string TokenEndpoint { get; set; } = "https://auth.zhengchentao.win/token";
|
||||
public string RegistrationEndpoint { get; set; } = "https://auth.zhengchentao.win/register";
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
namespace ObsidianMcp.Config;
|
||||
|
||||
/// <summary>
|
||||
/// Vault 根目录与路径安全配置。
|
||||
/// 环境变量前缀 Vault__,例如 Vault__Root=/vault
|
||||
/// </summary>
|
||||
public class VaultOptions
|
||||
{
|
||||
public const string Section = "Vault";
|
||||
|
||||
/// <summary>Vault 根目录的绝对路径,容器内默认 /vault</summary>
|
||||
public string Root { get; set; } = "/vault";
|
||||
|
||||
/// <summary>额外黑名单路径段(与 hardcode 合并),env: Vault__Blacklist__0, __1...</summary>
|
||||
public string[] Blacklist { get; set; } = [];
|
||||
|
||||
/// <summary>额外写入白名单前缀(与 hardcode 合并),env: Vault__WriteWhitelist__0...</summary>
|
||||
public string[] WriteWhitelist { get; set; } = [];
|
||||
}
|
||||
Reference in New Issue
Block a user