Skip to content

Commit d7fc02b

Browse files
committed
Add tool to find DEVONthink records by citation key and vice versa
1 parent 5a74386 commit d7fc02b

File tree

11 files changed

+1809
-4
lines changed

11 files changed

+1809
-4
lines changed

CLAUDE.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,12 @@
3333
- **`duplicateRecord.ts`**: Duplicates records to any database (creates independent copies)
3434
- **`convertRecord.ts`**: Converts records to different formats
3535
- **`updateRecordContent.ts`**: Updates the content of existing records while preserving UUID
36+
- **`getZoteroMetadata.ts`**: Looks up Zotero metadata for DEVONthink records using Finder paths or record identifiers
37+
- **`findRecordsByCitationKey.ts`**: Resolves Zotero citation keys to attachment metadata and matching DEVONthink records
3638
- **`src/utils/`**: Utility functions
3739
- **`escapeString.ts`**: Provides safe string escaping for JXA script interpolation
40+
- **`jxaHelpers.ts`**: Shared helper functions injected into JXA scripts for record lookup and conversion
41+
- **`zoteroMetadata.ts`**: Loads Zotero export files and resolves attachment metadata by Finder path
3842
- **`src/applescript/execute.ts`**: A utility module that provides the `executeJxa` function to run JXA scripts via the command line.
3943

4044
## Available Tools
@@ -64,6 +68,8 @@ The MCP server currently provides the following tools:
6468
21. **`duplicate_record`** - Duplicate records to any database (creates independent copies)
6569
22. **`convert_record`** - Convert records to different formats (plain text, rich text, markdown, HTML, PDF, etc.)
6670
23. **`update_record_content`** - Update the content of existing records while preserving UUID and metadata
71+
24. **`get_zotero_metadata`** - Look up Zotero attachment metadata for a DEVONthink record or Finder path, returning handy top-level `citationKey`, `zoteroId`, attachment listings, and a short `metadataSummary`
72+
25. **`find_records_by_citation_key`** - Resolve a Zotero citation key to its attachment metadata and any DEVONthink records whose Finder paths match those attachments
6773

6874
## Adding New Tools
6975

README.md

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
# Devonthink MCP Server
1+
Modified based on [dvcrn/mcp-server-devonthink](https://github.com/dvcrn/mcp-server-devonthink)
22

3-
This MCP server provides access to DEVONthink functionality via the Model Context Protocol (MCP). It enables listing, searching, creating, modifying, and managing records and databases in DEVONthink Pro on macOS.
3+
# DEVONthink Zotero MCP Server
4+
5+
This MCP server provides access to DEVONthink functionality via the Model Context Protocol (MCP). It enables listing, searching, creating, modifying, and managing records and databases in DEVONthink Pro on macOS. Additionally, it includes tools to resolve Zotero metadata for DEVONthink attachments based on exported Zotero data.
46

57
![screenshot](./screenshot.png)
68

@@ -12,6 +14,8 @@ This MCP server provides access to DEVONthink functionality via the Model Contex
1214
- Retrieve and modify record content, properties, and tags
1315
- Create records from URLs in multiple formats
1416
- List open databases and group contents
17+
- Resolve Zotero metadata for DEVONthink attachments via Zotero exports
18+
- Locate DEVONthink records directly from Zotero citation keys or attachment metadata
1519
- All tools are type-safe and validated with Zod schemas
1620

1721
## Tools
@@ -100,6 +104,16 @@ This MCP server provides access to DEVONthink functionality via the Model Contex
100104
- Input: primary record UUID, optional second record UUID, database name, and comparison type
101105
- Returns: Either similar records (single mode) or detailed comparison analysis (two-record mode)
102106

107+
17. `get_zotero_metadata`
108+
- Resolves Zotero metadata for a DEVONthink record or Finder path
109+
- Input: Finder path, record UUID, DEVONthink ID + database, or DEVONthink location path (optional `zoteroJsonPath` / `zoteroBibPath` override export locations)
110+
- Returns: The matched Zotero item with top-level `citationKey`, `zoteroId`, attachment list, and a short summary string for LLM prompts
111+
112+
18. `find_records_by_citation_key`
113+
- Resolves a Zotero citation key to its attachment metadata and matching DEVONthink records
114+
- Input: `citationKey` along with optional overrides for Zotero JSON/BibTeX export paths
115+
- Returns: Zotero metadata (JSON or BibTeX) plus any DEVONthink records whose Finder paths match the attachment entries
116+
103117
### Example: Search Tool
104118

105119
```json
@@ -144,3 +158,28 @@ Add to your Claude configuration:
144158
- Includes comprehensive tests using Vitest
145159

146160
See [CLAUDE.md](./CLAUDE.md) for full documentation, tool development guidelines, and API reference.
161+
162+
## Zotero Metadata Lookup
163+
164+
Zotero attachments stored in DEVONthink can be matched to exported Zotero metadata. The MCP server inspects both JSON and BibTeX exports and prefers JSON when both are present.
165+
166+
1. Export your Zotero library (or a subset) to `bibliography.json` and/or `bibliography.bib`.
167+
2. Point the server at the exports via environment variables before launching it (using Claude's MCP configuration or your shell):
168+
169+
```bash
170+
export ZOTERO_BIBLIOGRAPHY_JSON="/path/to/bibliography.json" # optional
171+
export ZOTERO_BIBLIOGRAPHY_BIB="/path/to/bibliography.bib" # optional
172+
```
173+
174+
- Supplying only one file is fine—the server detects whether you provided a `.json` or `.bib` path and uses it automatically.
175+
- If no metadata file is configured, the tool returns an informative error so you can correct the setup.
176+
177+
3. Call the `get_zotero_metadata` tool with a Finder path or any supported DEVONthink identifier. The tool returns the matched Zotero entry (including citation key, fields, and the property that matched), exposes `citationKey` / `zoteroId` at the top level, and provides a brief `metadataSummary` string for LLM prompts. If no match is found, the response lists the files that were checked.
178+
179+
Example invocation:
180+
181+
```json
182+
{
183+
"uuid": "7F8C5A5B-1234-5678-ABCD-9876543210EF"
184+
}
185+
```

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/devonthink.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ import { replicateRecordTool } from "./tools/replicateRecord.js";
3232
import { duplicateRecordTool } from "./tools/duplicateRecord.js";
3333
import { convertRecordTool } from "./tools/convertRecord.js";
3434
import { updateRecordContentTool } from "./tools/updateRecordContent.js";
35+
import { getZoteroMetadataTool } from "./tools/getZoteroMetadata.js";
36+
import { findRecordsByCitationKeyTool } from "./tools/findRecordsByCitationKey.js";
3537

3638
export const createServer = async () => {
3739
const server = new Server(
@@ -72,6 +74,8 @@ export const createServer = async () => {
7274
duplicateRecordTool,
7375
convertRecordTool,
7476
updateRecordContentTool,
77+
getZoteroMetadataTool,
78+
findRecordsByCitationKeyTool,
7579
];
7680

7781
server.setRequestHandler(ListToolsRequestSchema, async () => {

src/index.ts

100755100644
File mode changed.

0 commit comments

Comments
 (0)