@aniketbiswas/obsidian-mcp-server 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +232 -0
- package/build/index.d.ts +26 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +148 -0
- package/build/index.js.map +1 -0
- package/build/prompts/index.d.ts +33 -0
- package/build/prompts/index.d.ts.map +1 -0
- package/build/prompts/index.js +152 -0
- package/build/prompts/index.js.map +1 -0
- package/build/prompts/obsidian.d.ts +17 -0
- package/build/prompts/obsidian.d.ts.map +1 -0
- package/build/prompts/obsidian.js +305 -0
- package/build/prompts/obsidian.js.map +1 -0
- package/build/resources/index.d.ts +31 -0
- package/build/resources/index.d.ts.map +1 -0
- package/build/resources/index.js +111 -0
- package/build/resources/index.js.map +1 -0
- package/build/resources/obsidian.d.ts +19 -0
- package/build/resources/obsidian.d.ts.map +1 -0
- package/build/resources/obsidian.js +246 -0
- package/build/resources/obsidian.js.map +1 -0
- package/build/tools/_template.d.ts +23 -0
- package/build/tools/_template.d.ts.map +1 -0
- package/build/tools/_template.js +124 -0
- package/build/tools/_template.js.map +1 -0
- package/build/tools/calculator.d.ts +32 -0
- package/build/tools/calculator.d.ts.map +1 -0
- package/build/tools/calculator.js +130 -0
- package/build/tools/calculator.js.map +1 -0
- package/build/tools/daily-notes.d.ts +19 -0
- package/build/tools/daily-notes.d.ts.map +1 -0
- package/build/tools/daily-notes.js +469 -0
- package/build/tools/daily-notes.js.map +1 -0
- package/build/tools/greeting.d.ts +23 -0
- package/build/tools/greeting.d.ts.map +1 -0
- package/build/tools/greeting.js +111 -0
- package/build/tools/greeting.js.map +1 -0
- package/build/tools/index.d.ts +28 -0
- package/build/tools/index.d.ts.map +1 -0
- package/build/tools/index.js +46 -0
- package/build/tools/index.js.map +1 -0
- package/build/tools/links.d.ts +19 -0
- package/build/tools/links.d.ts.map +1 -0
- package/build/tools/links.js +467 -0
- package/build/tools/links.js.map +1 -0
- package/build/tools/metadata.d.ts +18 -0
- package/build/tools/metadata.d.ts.map +1 -0
- package/build/tools/metadata.js +447 -0
- package/build/tools/metadata.js.map +1 -0
- package/build/tools/navigation.d.ts +19 -0
- package/build/tools/navigation.d.ts.map +1 -0
- package/build/tools/navigation.js +378 -0
- package/build/tools/navigation.js.map +1 -0
- package/build/tools/notes.d.ts +19 -0
- package/build/tools/notes.d.ts.map +1 -0
- package/build/tools/notes.js +622 -0
- package/build/tools/notes.js.map +1 -0
- package/build/tools/search.d.ts +19 -0
- package/build/tools/search.d.ts.map +1 -0
- package/build/tools/search.js +418 -0
- package/build/tools/search.js.map +1 -0
- package/build/tools/templates.d.ts +18 -0
- package/build/tools/templates.d.ts.map +1 -0
- package/build/tools/templates.js +581 -0
- package/build/tools/templates.js.map +1 -0
- package/build/tools/vault.d.ts +19 -0
- package/build/tools/vault.d.ts.map +1 -0
- package/build/tools/vault.js +403 -0
- package/build/tools/vault.js.map +1 -0
- package/build/types/index.d.ts +11 -0
- package/build/types/index.d.ts.map +1 -0
- package/build/types/index.js +11 -0
- package/build/types/index.js.map +1 -0
- package/build/types/obsidian.d.ts +329 -0
- package/build/types/obsidian.d.ts.map +1 -0
- package/build/types/obsidian.js +38 -0
- package/build/types/obsidian.js.map +1 -0
- package/build/utils/client.d.ts +201 -0
- package/build/utils/client.d.ts.map +1 -0
- package/build/utils/client.js +656 -0
- package/build/utils/client.js.map +1 -0
- package/build/utils/config.d.ts +43 -0
- package/build/utils/config.d.ts.map +1 -0
- package/build/utils/config.js +117 -0
- package/build/utils/config.js.map +1 -0
- package/build/utils/frontmatter.d.ts +90 -0
- package/build/utils/frontmatter.d.ts.map +1 -0
- package/build/utils/frontmatter.js +306 -0
- package/build/utils/frontmatter.js.map +1 -0
- package/build/utils/index.d.ts +13 -0
- package/build/utils/index.d.ts.map +1 -0
- package/build/utils/index.js +13 -0
- package/build/utils/index.js.map +1 -0
- package/build/utils/markdown.d.ts +134 -0
- package/build/utils/markdown.d.ts.map +1 -0
- package/build/utils/markdown.js +330 -0
- package/build/utils/markdown.js.map +1 -0
- package/package.json +60 -0
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ============================================================================
|
|
3
|
+
* OBSIDIAN MCP - Resources
|
|
4
|
+
* ============================================================================
|
|
5
|
+
*
|
|
6
|
+
* MCP Resources provide read-only data that AI can access.
|
|
7
|
+
* These resources provide vault information and status data.
|
|
8
|
+
* ============================================================================
|
|
9
|
+
*/
|
|
10
|
+
import { CONFIG_DOCS } from "../utils/config.js";
|
|
11
|
+
/**
|
|
12
|
+
* Register Obsidian resources with the MCP server.
|
|
13
|
+
*
|
|
14
|
+
* @param server - The MCP server instance
|
|
15
|
+
* @param client - The Obsidian API client (or null if not configured)
|
|
16
|
+
*/
|
|
17
|
+
export function registerObsidianResources(server, client) {
|
|
18
|
+
// ---------------------------------------------------------------------------
|
|
19
|
+
// RESOURCE: obsidian-status
|
|
20
|
+
// ---------------------------------------------------------------------------
|
|
21
|
+
// Provides connection status and configuration info.
|
|
22
|
+
// ---------------------------------------------------------------------------
|
|
23
|
+
server.resource("obsidian-status", "mcp://obsidian/status", {
|
|
24
|
+
description: "Obsidian connection status and configuration information",
|
|
25
|
+
mimeType: "application/json",
|
|
26
|
+
}, async (uri) => {
|
|
27
|
+
let status;
|
|
28
|
+
if (!client) {
|
|
29
|
+
status = {
|
|
30
|
+
connected: false,
|
|
31
|
+
configured: false,
|
|
32
|
+
message: "Obsidian is not configured. Set OBSIDIAN_API_KEY environment variable.",
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
try {
|
|
37
|
+
const serverStatus = await client.getServerStatus();
|
|
38
|
+
status = {
|
|
39
|
+
connected: serverStatus.authenticated,
|
|
40
|
+
configured: true,
|
|
41
|
+
obsidianVersion: serverStatus.versions.obsidian,
|
|
42
|
+
apiVersion: serverStatus.versions.self,
|
|
43
|
+
service: serverStatus.service,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
status = {
|
|
48
|
+
connected: false,
|
|
49
|
+
configured: true,
|
|
50
|
+
error: error instanceof Error ? error.message : String(error),
|
|
51
|
+
message: "Failed to connect to Obsidian. Make sure it's running with Local REST API enabled.",
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
contents: [
|
|
57
|
+
{
|
|
58
|
+
uri: uri.href,
|
|
59
|
+
mimeType: "application/json",
|
|
60
|
+
text: JSON.stringify(status, null, 2),
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
};
|
|
64
|
+
});
|
|
65
|
+
// ---------------------------------------------------------------------------
|
|
66
|
+
// RESOURCE: obsidian-help
|
|
67
|
+
// ---------------------------------------------------------------------------
|
|
68
|
+
// Provides documentation and available tools list.
|
|
69
|
+
// ---------------------------------------------------------------------------
|
|
70
|
+
server.resource("obsidian-help", "mcp://obsidian/help", {
|
|
71
|
+
description: "Documentation and help for the Obsidian MCP server",
|
|
72
|
+
mimeType: "text/markdown",
|
|
73
|
+
}, async (uri) => ({
|
|
74
|
+
contents: [
|
|
75
|
+
{
|
|
76
|
+
uri: uri.href,
|
|
77
|
+
mimeType: "text/markdown",
|
|
78
|
+
text: `# Obsidian MCP Server
|
|
79
|
+
|
|
80
|
+
This MCP server provides tools for interacting with your Obsidian vault through any MCP-compatible AI assistant.
|
|
81
|
+
|
|
82
|
+
## Prerequisites
|
|
83
|
+
|
|
84
|
+
1. **Obsidian** must be running
|
|
85
|
+
2. **Local REST API plugin** must be installed and enabled
|
|
86
|
+
3. **API Key** must be configured via environment variable
|
|
87
|
+
|
|
88
|
+
## Configuration
|
|
89
|
+
|
|
90
|
+
\`\`\`
|
|
91
|
+
${CONFIG_DOCS}
|
|
92
|
+
\`\`\`
|
|
93
|
+
|
|
94
|
+
## Available Tool Categories
|
|
95
|
+
|
|
96
|
+
### Vault Management
|
|
97
|
+
- \`vault_status\` - Check connection status
|
|
98
|
+
- \`list_files\` - List files in a directory
|
|
99
|
+
- \`list_all_files\` - Recursively list all files
|
|
100
|
+
- \`get_vault_structure\` - Get folder tree structure
|
|
101
|
+
- \`get_file_stats\` - Get vault statistics
|
|
102
|
+
|
|
103
|
+
### Note Operations
|
|
104
|
+
- \`read_note\` - Read note content
|
|
105
|
+
- \`create_note\` - Create a new note
|
|
106
|
+
- \`update_note\` - Update note content
|
|
107
|
+
- \`append_to_note\` - Append to a note
|
|
108
|
+
- \`prepend_to_note\` - Prepend to a note
|
|
109
|
+
- \`insert_under_heading\` - Insert under specific heading
|
|
110
|
+
- \`replace_in_note\` - Find and replace text
|
|
111
|
+
- \`delete_note\` - Delete a note
|
|
112
|
+
- \`copy_note\` - Copy a note
|
|
113
|
+
|
|
114
|
+
### Search
|
|
115
|
+
- \`search_notes\` - Full-text search with Obsidian syntax
|
|
116
|
+
- \`simple_search\` - Simple text search
|
|
117
|
+
- \`search_by_tag\` - Find notes by tags
|
|
118
|
+
- \`search_in_folder\` - Search within a folder
|
|
119
|
+
- \`find_notes_by_name\` - Find by filename
|
|
120
|
+
- \`search_with_context\` - Search with content snippets
|
|
121
|
+
|
|
122
|
+
### Metadata & Tags
|
|
123
|
+
- \`get_frontmatter\` - Get note frontmatter
|
|
124
|
+
- \`update_frontmatter\` - Update frontmatter properties
|
|
125
|
+
- \`set_frontmatter_property\` - Set single property
|
|
126
|
+
- \`get_tags\` - Get all tags from a note
|
|
127
|
+
- \`add_tags\` - Add tags to a note
|
|
128
|
+
- \`remove_tags\` - Remove tags from a note
|
|
129
|
+
- \`add_aliases\` - Add note aliases
|
|
130
|
+
- \`get_all_tags_in_vault\` - Get all tags in vault
|
|
131
|
+
|
|
132
|
+
### Navigation & Commands
|
|
133
|
+
- \`open_note\` - Open note in Obsidian
|
|
134
|
+
- \`get_active_note\` - Get currently active note
|
|
135
|
+
- \`append_to_active_note\` - Append to active note
|
|
136
|
+
- \`get_commands\` - List Obsidian commands
|
|
137
|
+
- \`execute_command\` - Execute a command
|
|
138
|
+
- \`quick_capture\` - Quick capture to inbox
|
|
139
|
+
|
|
140
|
+
### Daily & Periodic Notes
|
|
141
|
+
- \`get_daily_note\` - Get today's daily note
|
|
142
|
+
- \`append_to_daily_note\` - Append to daily note
|
|
143
|
+
- \`get_periodic_note\` - Get periodic note
|
|
144
|
+
- \`append_to_periodic_note\` - Append to periodic note
|
|
145
|
+
- \`daily_journal_entry\` - Add journal entry
|
|
146
|
+
- \`daily_standup\` - Add standup entry
|
|
147
|
+
|
|
148
|
+
### Link Analysis
|
|
149
|
+
- \`get_outgoing_links\` - Get links from a note
|
|
150
|
+
- \`get_backlinks\` - Find backlinks to a note
|
|
151
|
+
- \`find_broken_links\` - Find broken links
|
|
152
|
+
- \`find_orphan_notes\` - Find unlinked notes
|
|
153
|
+
- \`add_link_to_note\` - Add a link to a note
|
|
154
|
+
- \`get_link_graph_data\` - Get graph visualization data
|
|
155
|
+
|
|
156
|
+
### Templates
|
|
157
|
+
- \`create_note_from_template\` - Create from template
|
|
158
|
+
- \`create_meeting_note\` - Create meeting note
|
|
159
|
+
- \`create_project_note\` - Create project note
|
|
160
|
+
- \`list_templates\` - List available templates
|
|
161
|
+
|
|
162
|
+
## Examples
|
|
163
|
+
|
|
164
|
+
### Create a new note
|
|
165
|
+
"Create a note called 'Meeting Notes' in the Meetings folder with today's date"
|
|
166
|
+
|
|
167
|
+
### Search vault
|
|
168
|
+
"Search for notes about machine learning"
|
|
169
|
+
"Find all notes tagged with #project"
|
|
170
|
+
|
|
171
|
+
### Daily notes
|
|
172
|
+
"Add this task to today's daily note"
|
|
173
|
+
"Create a journal entry with today's highlights"
|
|
174
|
+
|
|
175
|
+
### Analyze links
|
|
176
|
+
"Find all notes that link to my 'Project Overview' note"
|
|
177
|
+
"Show me orphan notes that need to be linked"
|
|
178
|
+
|
|
179
|
+
## Tips
|
|
180
|
+
|
|
181
|
+
- Use wikilinks format: \`[[Note Name]]\` for internal links
|
|
182
|
+
- Tags can be in frontmatter or inline: \`#tag\`
|
|
183
|
+
- Obsidian search syntax works in \`search_notes\`
|
|
184
|
+
- Daily notes require the Daily Notes core plugin
|
|
185
|
+
`,
|
|
186
|
+
},
|
|
187
|
+
],
|
|
188
|
+
}));
|
|
189
|
+
// ---------------------------------------------------------------------------
|
|
190
|
+
// RESOURCE: obsidian-vault-info
|
|
191
|
+
// ---------------------------------------------------------------------------
|
|
192
|
+
// Provides vault structure information.
|
|
193
|
+
// ---------------------------------------------------------------------------
|
|
194
|
+
if (client) {
|
|
195
|
+
server.resource("obsidian-vault-info", "mcp://obsidian/vault-info", {
|
|
196
|
+
description: "Information about the Obsidian vault structure",
|
|
197
|
+
mimeType: "application/json",
|
|
198
|
+
}, async (uri) => {
|
|
199
|
+
try {
|
|
200
|
+
const allFiles = await client.listAllFiles("", 5);
|
|
201
|
+
const mdFiles = allFiles.filter((f) => f.type === "file" && f.extension === "md");
|
|
202
|
+
const directories = allFiles.filter((f) => f.type === "directory");
|
|
203
|
+
// Count by extension
|
|
204
|
+
const extensionCounts = {};
|
|
205
|
+
for (const file of allFiles.filter((f) => f.type === "file")) {
|
|
206
|
+
const ext = file.extension || "no-extension";
|
|
207
|
+
extensionCounts[ext] = (extensionCounts[ext] || 0) + 1;
|
|
208
|
+
}
|
|
209
|
+
const info = {
|
|
210
|
+
totalFiles: allFiles.filter((f) => f.type === "file").length,
|
|
211
|
+
markdownNotes: mdFiles.length,
|
|
212
|
+
directories: directories.length,
|
|
213
|
+
extensionCounts,
|
|
214
|
+
topLevelFolders: directories
|
|
215
|
+
.filter((d) => !d.path.includes("/"))
|
|
216
|
+
.map((d) => d.name)
|
|
217
|
+
.slice(0, 20),
|
|
218
|
+
};
|
|
219
|
+
return {
|
|
220
|
+
contents: [
|
|
221
|
+
{
|
|
222
|
+
uri: uri.href,
|
|
223
|
+
mimeType: "application/json",
|
|
224
|
+
text: JSON.stringify(info, null, 2),
|
|
225
|
+
},
|
|
226
|
+
],
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
catch (error) {
|
|
230
|
+
return {
|
|
231
|
+
contents: [
|
|
232
|
+
{
|
|
233
|
+
uri: uri.href,
|
|
234
|
+
mimeType: "application/json",
|
|
235
|
+
text: JSON.stringify({
|
|
236
|
+
error: error instanceof Error ? error.message : String(error),
|
|
237
|
+
}, null, 2),
|
|
238
|
+
},
|
|
239
|
+
],
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
console.error("✅ Obsidian resources registered");
|
|
245
|
+
}
|
|
246
|
+
//# sourceMappingURL=obsidian.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"obsidian.js","sourceRoot":"","sources":["../../src/resources/obsidian.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,EAAgB,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAE/D;;;;;GAKG;AACH,MAAM,UAAU,yBAAyB,CACvC,MAAiB,EACjB,MAA6B;IAE7B,8EAA8E;IAC9E,4BAA4B;IAC5B,8EAA8E;IAC9E,qDAAqD;IACrD,8EAA8E;IAE9E,MAAM,CAAC,QAAQ,CACb,iBAAiB,EACjB,uBAAuB,EACvB;QACE,WAAW,EAAE,0DAA0D;QACvE,QAAQ,EAAE,kBAAkB;KAC7B,EACD,KAAK,EAAE,GAAG,EAAE,EAAE;QACZ,IAAI,MAA+B,CAAC;QAEpC,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,GAAG;gBACP,SAAS,EAAE,KAAK;gBAChB,UAAU,EAAE,KAAK;gBACjB,OAAO,EAAE,wEAAwE;aAClF,CAAC;QACJ,CAAC;aAAM,CAAC;YACN,IAAI,CAAC;gBACH,MAAM,YAAY,GAAG,MAAM,MAAM,CAAC,eAAe,EAAE,CAAC;gBACpD,MAAM,GAAG;oBACP,SAAS,EAAE,YAAY,CAAC,aAAa;oBACrC,UAAU,EAAE,IAAI;oBAChB,eAAe,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AM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;yBACpC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;yBAClB,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC;iBAChB,CAAC;gBAEF,OAAO;oBACL,QAAQ,EAAE;wBACR;4BACE,GAAG,EAAE,GAAG,CAAC,IAAI;4BACb,QAAQ,EAAE,kBAAkB;4BAC5B,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;yBACpC;qBACF;iBACF,CAAC;YACJ,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,OAAO;oBACL,QAAQ,EAAE;wBACR;4BACE,GAAG,EAAE,GAAG,CAAC,IAAI;4BACb,QAAQ,EAAE,kBAAkB;4BAC5B,IAAI,EAAE,IAAI,CAAC,SAAS,CAClB;gCACE,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;6BAC9D,EACD,IAAI,EACJ,CAAC,CACF;yBACF;qBACF;iBACF,CAAC;YACJ,CAAC;QACH,CAAC,CACF,CAAC;IACJ,CAAC;IAED,OAAO,CAAC,KAAK,CAAC,iCAAiC,CAAC,CAAC;AACnD,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ============================================================================
|
|
3
|
+
* TOOL TEMPLATE - Copy This File to Create Your Own Tools!
|
|
4
|
+
* ============================================================================
|
|
5
|
+
*
|
|
6
|
+
* QUICK START:
|
|
7
|
+
* 1. Copy this file: cp src/tools/_template.ts src/tools/my-tools.ts
|
|
8
|
+
* 2. Rename the function: registerTemplateTools → registerMyTools
|
|
9
|
+
* 3. Add your tools inside the function
|
|
10
|
+
* 4. Register in src/index.ts:
|
|
11
|
+
* - import { registerMyTools } from "./tools/my-tools.js";
|
|
12
|
+
* - registerMyTools(server);
|
|
13
|
+
* 5. Build and test: npm run build && npm run inspector
|
|
14
|
+
*
|
|
15
|
+
* ============================================================================
|
|
16
|
+
*/
|
|
17
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
18
|
+
/**
|
|
19
|
+
* Register your custom tools here.
|
|
20
|
+
* Rename this function to match your file name!
|
|
21
|
+
*/
|
|
22
|
+
export declare function registerTemplateTools(server: McpServer): void;
|
|
23
|
+
//# sourceMappingURL=_template.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_template.d.ts","sourceRoot":"","sources":["../../src/tools/_template.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAGpE;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,CAoG7D"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ============================================================================
|
|
3
|
+
* TOOL TEMPLATE - Copy This File to Create Your Own Tools!
|
|
4
|
+
* ============================================================================
|
|
5
|
+
*
|
|
6
|
+
* QUICK START:
|
|
7
|
+
* 1. Copy this file: cp src/tools/_template.ts src/tools/my-tools.ts
|
|
8
|
+
* 2. Rename the function: registerTemplateTools → registerMyTools
|
|
9
|
+
* 3. Add your tools inside the function
|
|
10
|
+
* 4. Register in src/index.ts:
|
|
11
|
+
* - import { registerMyTools } from "./tools/my-tools.js";
|
|
12
|
+
* - registerMyTools(server);
|
|
13
|
+
* 5. Build and test: npm run build && npm run inspector
|
|
14
|
+
*
|
|
15
|
+
* ============================================================================
|
|
16
|
+
*/
|
|
17
|
+
import { z } from "zod";
|
|
18
|
+
/**
|
|
19
|
+
* Register your custom tools here.
|
|
20
|
+
* Rename this function to match your file name!
|
|
21
|
+
*/
|
|
22
|
+
export function registerTemplateTools(server) {
|
|
23
|
+
// ---------------------------------------------------------------------------
|
|
24
|
+
// EXAMPLE: Simple tool with one parameter
|
|
25
|
+
// ---------------------------------------------------------------------------
|
|
26
|
+
server.tool("example_tool", // Tool name
|
|
27
|
+
"An example tool - replace with your own!", // Description
|
|
28
|
+
{
|
|
29
|
+
input: z.string().describe("Your input parameter"),
|
|
30
|
+
}, async ({ input }) => {
|
|
31
|
+
// Your logic here!
|
|
32
|
+
const result = `You said: ${input}`;
|
|
33
|
+
return {
|
|
34
|
+
content: [{ type: "text", text: result }],
|
|
35
|
+
};
|
|
36
|
+
});
|
|
37
|
+
// ---------------------------------------------------------------------------
|
|
38
|
+
// EXAMPLE: Tool with multiple parameters
|
|
39
|
+
// ---------------------------------------------------------------------------
|
|
40
|
+
server.tool("example_multi_param", "Example with multiple parameters", {
|
|
41
|
+
required_param: z.string().describe("This is required"),
|
|
42
|
+
optional_param: z.string().optional().describe("This is optional"),
|
|
43
|
+
number_param: z.number().describe("A number input"),
|
|
44
|
+
choice_param: z.enum(["option1", "option2", "option3"]).describe("Pick one"),
|
|
45
|
+
}, async ({ required_param, optional_param, number_param, choice_param }) => {
|
|
46
|
+
return {
|
|
47
|
+
content: [{
|
|
48
|
+
type: "text",
|
|
49
|
+
text: `Required: ${required_param}, Optional: ${optional_param || "not provided"}, Number: ${number_param}, Choice: ${choice_param}`,
|
|
50
|
+
}],
|
|
51
|
+
};
|
|
52
|
+
});
|
|
53
|
+
// ---------------------------------------------------------------------------
|
|
54
|
+
// EXAMPLE: Tool with error handling
|
|
55
|
+
// ---------------------------------------------------------------------------
|
|
56
|
+
server.tool("example_with_error", "Example showing error handling", {
|
|
57
|
+
value: z.number().describe("A positive number"),
|
|
58
|
+
}, async ({ value }) => {
|
|
59
|
+
// Validate and handle errors
|
|
60
|
+
if (value < 0) {
|
|
61
|
+
return {
|
|
62
|
+
content: [{ type: "text", text: "Error: Value must be positive!" }],
|
|
63
|
+
isError: true, // Marks this as an error response
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
content: [{ type: "text", text: `Success! Value is ${value}` }],
|
|
68
|
+
};
|
|
69
|
+
});
|
|
70
|
+
// ---------------------------------------------------------------------------
|
|
71
|
+
// EXAMPLE: Async tool (API calls, file operations, etc.)
|
|
72
|
+
// ---------------------------------------------------------------------------
|
|
73
|
+
server.tool("example_async", "Example with async operations", {
|
|
74
|
+
url: z.string().url().describe("A URL to fetch"),
|
|
75
|
+
}, async ({ url }) => {
|
|
76
|
+
try {
|
|
77
|
+
// Example: fetch data from an API
|
|
78
|
+
// const response = await fetch(url);
|
|
79
|
+
// const data = await response.json();
|
|
80
|
+
// Simulated async operation
|
|
81
|
+
await new Promise(resolve => setTimeout(resolve, 100));
|
|
82
|
+
return {
|
|
83
|
+
content: [{ type: "text", text: `Would fetch: ${url}` }],
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
return {
|
|
88
|
+
content: [{ type: "text", text: `Error fetching URL: ${error}` }],
|
|
89
|
+
isError: true,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
// =============================================================================
|
|
95
|
+
// ZOD TYPE REFERENCE
|
|
96
|
+
// =============================================================================
|
|
97
|
+
//
|
|
98
|
+
// BASIC TYPES:
|
|
99
|
+
// z.string() - Text
|
|
100
|
+
// z.number() - Number (int or float)
|
|
101
|
+
// z.boolean() - True/false
|
|
102
|
+
// z.date() - Date object
|
|
103
|
+
//
|
|
104
|
+
// MODIFIERS:
|
|
105
|
+
// .optional() - Not required
|
|
106
|
+
// .default("value") - Default value if not provided
|
|
107
|
+
// .describe("text") - Description for AI
|
|
108
|
+
//
|
|
109
|
+
// VALIDATIONS:
|
|
110
|
+
// z.string().min(1) - Minimum length
|
|
111
|
+
// z.string().max(100) - Maximum length
|
|
112
|
+
// z.string().email() - Must be email
|
|
113
|
+
// z.string().url() - Must be URL
|
|
114
|
+
// z.number().min(0) - Minimum value
|
|
115
|
+
// z.number().max(100) - Maximum value
|
|
116
|
+
// z.number().int() - Must be integer
|
|
117
|
+
//
|
|
118
|
+
// COMPLEX TYPES:
|
|
119
|
+
// z.enum(["a", "b", "c"]) - One of specific values
|
|
120
|
+
// z.array(z.string()) - Array of strings
|
|
121
|
+
// z.object({ key: z.string() }) - Nested object
|
|
122
|
+
//
|
|
123
|
+
// =============================================================================
|
|
124
|
+
//# sourceMappingURL=_template.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_template.js","sourceRoot":"","sources":["../../src/tools/_template.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;GAGG;AACH,MAAM,UAAU,qBAAqB,CAAC,MAAiB;IAErD,8EAA8E;IAC9E,0CAA0C;IAC1C,8EAA8E;IAE9E,MAAM,CAAC,IAAI,CACT,cAAc,EAAqC,YAAY;IAC/D,0CAA0C,EAAQ,cAAc;IAChE;QACE,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,sBAAsB,CAAC;KACnD,EACD,KAAK,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE;QAClB,mBAAmB;QACnB,MAAM,MAAM,GAAG,aAAa,KAAK,EAAE,CAAC;QAEpC,OAAO;YACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;SAC1C,CAAC;IACJ,CAAC,CACF,CAAC;IAEF,8EAA8E;IAC9E,yCAAyC;IACzC,8EAA8E;IAE9E,MAAM,CAAC,IAAI,CACT,qBAAqB,EACrB,kCAAkC,EAClC;QACE,cAAc,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,kBAAkB,CAAC;QACvD,cAAc,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ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AAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,gBAAgB,CAAC;KACjD,EACD,KAAK,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE;QAChB,IAAI,CAAC;YACH,kCAAkC;YAClC,qCAAqC;YACrC,sCAAsC;YAEtC,4BAA4B;YAC5B,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC;YAEvD,OAAO;gBACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,gBAAgB,GAAG,EAAE,EAAE,CAAC;aACzD,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO;gBACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,uBAAuB,KAAK,EAAE,EAAE,CAAC;gBACjE,OAAO,EAAE,IAAI;aACd,CAAC;QACJ,CAAC;IACH,CAAC,CACF,CAAC;AACJ,CAAC;AAED,gFAAgF;AAChF,qBAAqB;AACrB,gFAAgF;AAChF,EAAE;AACF,eAAe;AACf,yCAAyC;AACzC,0DAA0D;AAC1D,+CAA+C;AAC/C,gDAAgD;AAChD,EAAE;AACF,aAAa;AACb,iDAAiD;AACjD,kEAAkE;AAClE,uDAAuD;AACvD,EAAE;AACF,eAAe;AACf,mDAAmD;AACnD,mDAAmD;AACnD,kDAAkD;AAClD,gDAAgD;AAChD,kDAAkD;AAClD,kDAAkD;AAClD,oDAAoD;AACpD,EAAE;AACF,iBAAiB;AACjB,2DAA2D;AAC3D,qDAAqD;AACrD,kDAAkD;AAClD,EAAE;AACF,gFAAgF"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ============================================================================
|
|
3
|
+
* CALCULATOR TOOLS - Example MCP Tools
|
|
4
|
+
* ============================================================================
|
|
5
|
+
*
|
|
6
|
+
* This file shows how to create MCP tools step by step.
|
|
7
|
+
* Use this as a template when creating your own tools!
|
|
8
|
+
*
|
|
9
|
+
* WHAT IS A TOOL?
|
|
10
|
+
* A tool is a function that AI can call. When a user asks Claude to
|
|
11
|
+
* "add 5 and 3", Claude will call your 'add' tool with {a: 5, b: 3}.
|
|
12
|
+
*
|
|
13
|
+
* ANATOMY OF A TOOL:
|
|
14
|
+
*
|
|
15
|
+
* server.tool(
|
|
16
|
+
* "tool_name", // Unique name (lowercase, underscores ok)
|
|
17
|
+
* "Description", // What the tool does (AI reads this!)
|
|
18
|
+
* { params }, // Input parameters with Zod validation
|
|
19
|
+
* async (inputs) => {} // Your function that does the work
|
|
20
|
+
* );
|
|
21
|
+
*
|
|
22
|
+
* COPY THIS FILE to create your own tools!
|
|
23
|
+
* ============================================================================
|
|
24
|
+
*/
|
|
25
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
26
|
+
/**
|
|
27
|
+
* Registers all calculator tools with the MCP server.
|
|
28
|
+
*
|
|
29
|
+
* @param server - The MCP server instance to register tools with
|
|
30
|
+
*/
|
|
31
|
+
export declare function registerCalculatorTools(server: McpServer): void;
|
|
32
|
+
//# sourceMappingURL=calculator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calculator.d.ts","sourceRoot":"","sources":["../../src/tools/calculator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAGpE;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,CAgH/D"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ============================================================================
|
|
3
|
+
* CALCULATOR TOOLS - Example MCP Tools
|
|
4
|
+
* ============================================================================
|
|
5
|
+
*
|
|
6
|
+
* This file shows how to create MCP tools step by step.
|
|
7
|
+
* Use this as a template when creating your own tools!
|
|
8
|
+
*
|
|
9
|
+
* WHAT IS A TOOL?
|
|
10
|
+
* A tool is a function that AI can call. When a user asks Claude to
|
|
11
|
+
* "add 5 and 3", Claude will call your 'add' tool with {a: 5, b: 3}.
|
|
12
|
+
*
|
|
13
|
+
* ANATOMY OF A TOOL:
|
|
14
|
+
*
|
|
15
|
+
* server.tool(
|
|
16
|
+
* "tool_name", // Unique name (lowercase, underscores ok)
|
|
17
|
+
* "Description", // What the tool does (AI reads this!)
|
|
18
|
+
* { params }, // Input parameters with Zod validation
|
|
19
|
+
* async (inputs) => {} // Your function that does the work
|
|
20
|
+
* );
|
|
21
|
+
*
|
|
22
|
+
* COPY THIS FILE to create your own tools!
|
|
23
|
+
* ============================================================================
|
|
24
|
+
*/
|
|
25
|
+
import { z } from "zod"; // Zod validates that inputs are the correct type
|
|
26
|
+
/**
|
|
27
|
+
* Registers all calculator tools with the MCP server.
|
|
28
|
+
*
|
|
29
|
+
* @param server - The MCP server instance to register tools with
|
|
30
|
+
*/
|
|
31
|
+
export function registerCalculatorTools(server) {
|
|
32
|
+
// ---------------------------------------------------------------------------
|
|
33
|
+
// TOOL: add
|
|
34
|
+
// ---------------------------------------------------------------------------
|
|
35
|
+
// This is the simplest possible tool - takes two numbers, returns their sum.
|
|
36
|
+
// ---------------------------------------------------------------------------
|
|
37
|
+
server.tool(
|
|
38
|
+
// 1. TOOL NAME - must be unique across all your tools
|
|
39
|
+
"add",
|
|
40
|
+
// 2. DESCRIPTION - AI uses this to decide when to call your tool
|
|
41
|
+
// Write it clearly! The better the description, the better AI uses it.
|
|
42
|
+
"Add two numbers together",
|
|
43
|
+
// 3. INPUT SCHEMA - defines what parameters the tool accepts
|
|
44
|
+
// Uses Zod for validation: z.number(), z.string(), z.boolean(), etc.
|
|
45
|
+
// .describe() helps AI understand what each parameter is for
|
|
46
|
+
{
|
|
47
|
+
a: z.number().describe("First number to add"),
|
|
48
|
+
b: z.number().describe("Second number to add"),
|
|
49
|
+
},
|
|
50
|
+
// 4. HANDLER FUNCTION - this runs when AI calls your tool
|
|
51
|
+
// Receives validated inputs, must return a content array
|
|
52
|
+
async ({ a, b }) => {
|
|
53
|
+
// Your tool logic goes here!
|
|
54
|
+
const result = a + b;
|
|
55
|
+
// Return format: array of content blocks
|
|
56
|
+
// Most common: { type: "text", text: "your result" }
|
|
57
|
+
return {
|
|
58
|
+
content: [
|
|
59
|
+
{
|
|
60
|
+
type: "text",
|
|
61
|
+
text: `${a} + ${b} = ${result}`,
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
};
|
|
65
|
+
});
|
|
66
|
+
// ---------------------------------------------------------------------------
|
|
67
|
+
// TOOL: subtract
|
|
68
|
+
// ---------------------------------------------------------------------------
|
|
69
|
+
server.tool("subtract", "Subtract the second number from the first", {
|
|
70
|
+
a: z.number().describe("Number to subtract from"),
|
|
71
|
+
b: z.number().describe("Number to subtract"),
|
|
72
|
+
}, async ({ a, b }) => {
|
|
73
|
+
const result = a - b;
|
|
74
|
+
return {
|
|
75
|
+
content: [{ type: "text", text: `${a} - ${b} = ${result}` }],
|
|
76
|
+
};
|
|
77
|
+
});
|
|
78
|
+
// ---------------------------------------------------------------------------
|
|
79
|
+
// TOOL: multiply
|
|
80
|
+
// ---------------------------------------------------------------------------
|
|
81
|
+
server.tool("multiply", "Multiply two numbers together", {
|
|
82
|
+
a: z.number().describe("First number to multiply"),
|
|
83
|
+
b: z.number().describe("Second number to multiply"),
|
|
84
|
+
}, async ({ a, b }) => {
|
|
85
|
+
const result = a * b;
|
|
86
|
+
return {
|
|
87
|
+
content: [{ type: "text", text: `${a} × ${b} = ${result}` }],
|
|
88
|
+
};
|
|
89
|
+
});
|
|
90
|
+
// ---------------------------------------------------------------------------
|
|
91
|
+
// TOOL: divide (with error handling example)
|
|
92
|
+
// ---------------------------------------------------------------------------
|
|
93
|
+
// This tool shows how to handle errors gracefully.
|
|
94
|
+
// Set isError: true to tell AI the operation failed.
|
|
95
|
+
// ---------------------------------------------------------------------------
|
|
96
|
+
server.tool("divide", "Divide the first number by the second", {
|
|
97
|
+
a: z.number().describe("Dividend (number to be divided)"),
|
|
98
|
+
b: z.number().describe("Divisor (number to divide by)"),
|
|
99
|
+
}, async ({ a, b }) => {
|
|
100
|
+
// Always validate inputs and handle edge cases!
|
|
101
|
+
if (b === 0) {
|
|
102
|
+
return {
|
|
103
|
+
content: [
|
|
104
|
+
{ type: "text", text: "Error: Cannot divide by zero" },
|
|
105
|
+
],
|
|
106
|
+
isError: true, // Tells AI this is an error response
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
const result = a / b;
|
|
110
|
+
return {
|
|
111
|
+
content: [{ type: "text", text: `${a} ÷ ${b} = ${result}` }],
|
|
112
|
+
};
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
// =============================================================================
|
|
116
|
+
// QUICK REFERENCE: Zod Types You Can Use
|
|
117
|
+
// =============================================================================
|
|
118
|
+
//
|
|
119
|
+
// z.string() - Text input
|
|
120
|
+
// z.number() - Numeric input
|
|
121
|
+
// z.boolean() - True/false
|
|
122
|
+
// z.enum(["a", "b"]) - One of specific values
|
|
123
|
+
// z.array(z.string()) - Array of strings
|
|
124
|
+
// z.object({...}) - Nested object
|
|
125
|
+
// z.optional() - Makes parameter optional
|
|
126
|
+
// z.default("value") - Provides default value
|
|
127
|
+
//
|
|
128
|
+
// Chain them: z.string().optional().describe("Optional text")
|
|
129
|
+
// =============================================================================
|
|
130
|
+
//# sourceMappingURL=calculator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calculator.js","sourceRoot":"","sources":["../../src/tools/calculator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAGH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC,CAAE,iDAAiD;AAE3E;;;;GAIG;AACH,MAAM,UAAU,uBAAuB,CAAC,MAAiB;IAEvD,8EAA8E;IAC9E,YAAY;IACZ,8EA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G,CAAC,MAAM,CAAC,MAAM,MAAM,EAAE,EAAE,CAAC;SAC7D,CAAC;IACJ,CAAC,CACF,CAAC;AACJ,CAAC;AAED,gFAAgF;AAChF,yCAAyC;AACzC,gFAAgF;AAChF,EAAE;AACF,oCAAoC;AACpC,uCAAuC;AACvC,oCAAoC;AACpC,gDAAgD;AAChD,0CAA0C;AAC1C,uCAAuC;AACvC,kDAAkD;AAClD,gDAAgD;AAChD,EAAE;AACF,8DAA8D;AAC9D,gFAAgF"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ============================================================================
|
|
3
|
+
* OBSIDIAN MCP - Daily/Periodic Notes Tools
|
|
4
|
+
* ============================================================================
|
|
5
|
+
*
|
|
6
|
+
* Tools for working with daily notes, weekly notes, and other periodic notes.
|
|
7
|
+
* Requires the Periodic Notes plugin or Daily Notes core plugin in Obsidian.
|
|
8
|
+
* ============================================================================
|
|
9
|
+
*/
|
|
10
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
11
|
+
import { ObsidianClient } from "../utils/client.js";
|
|
12
|
+
/**
|
|
13
|
+
* Register daily/periodic notes tools with the MCP server.
|
|
14
|
+
*
|
|
15
|
+
* @param server - The MCP server instance
|
|
16
|
+
* @param client - The Obsidian API client
|
|
17
|
+
*/
|
|
18
|
+
export declare function registerDailyNotesTools(server: McpServer, client: ObsidianClient): void;
|
|
19
|
+
//# sourceMappingURL=daily-notes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"daily-notes.d.ts","sourceRoot":"","sources":["../../src/tools/daily-notes.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAEpE,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAIpD;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,SAAS,EACjB,MAAM,EAAE,cAAc,GACrB,IAAI,CA8iBN"}
|