Skip to content

Commit 786cd62

Browse files
committed
refactor: reorganize file structure and update documentation
- Reorganize project files for improved maintainability - Add project structure documentation to README.md
1 parent 93adc5a commit 786cd62

File tree

11 files changed

+1870
-1747
lines changed

11 files changed

+1870
-1747
lines changed

README.md

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ or
6969
- `--enabledTools`: Comma-separated list of tools to enable (e.g. "notion_retrieve_page,notion_query_database"). When specified, only the listed tools will be available. If not specified, all tools are enabled.
7070

7171
Read-only tools example (copy-paste friendly):
72+
7273
```bash
7374
node build/index.js --enabledTools=notion_retrieve_block,notion_retrieve_block_children,notion_retrieve_page,notion_query_database,notion_retrieve_database,notion_search,notion_list_all_users,notion_retrieve_user,notion_retrieve_bot_user,notion_retrieve_comments
7475
```
@@ -126,6 +127,48 @@ If you encounter permission errors:
126127
2. Verify that the integration is invited to the relevant pages or databases.
127128
3. Confirm the token and configuration are correctly set in `claude_desktop_config.json`.
128129

130+
## Project Structure
131+
132+
The project is organized in a modular way to improve maintainability and readability:
133+
134+
```
135+
notion/
136+
├── src/
137+
│ ├── index.ts # Entry point and command-line handling
138+
│ ├── client/
139+
│ │ └── index.ts # NotionClientWrapper class for API interactions
140+
│ ├── server/
141+
│ │ └── index.ts # MCP server setup and request handling
142+
│ ├── types/
143+
│ │ ├── index.ts # Type exports
144+
│ │ ├── args.ts # Tool argument interfaces
145+
│ │ ├── common.ts # Common schema definitions
146+
│ │ ├── responses.ts # API response type definitions
147+
│ │ └── schemas.ts # Tool schema definitions
148+
│ ├── utils/
149+
│ │ └── index.ts # Utility functions
150+
│ └── markdown/
151+
│ └── index.ts # Markdown conversion utilities
152+
```
153+
154+
### Directory Descriptions
155+
156+
- **index.ts**: Application entry point. Parses command-line arguments and starts the server.
157+
- **client/**: Module responsible for communication with the Notion API.
158+
- **index.ts**: NotionClientWrapper class implements all API calls.
159+
- **server/**: MCP server implementation.
160+
- **index.ts**: Processes requests received from Claude and calls appropriate client methods.
161+
- **types/**: Type definition module.
162+
- **index.ts**: Exports for all types.
163+
- **args.ts**: Interface definitions for tool arguments.
164+
- **common.ts**: Definitions for common schemas (ID formats, rich text, etc.).
165+
- **responses.ts**: Type definitions for Notion API responses.
166+
- **schemas.ts**: Definitions for MCP tool schemas.
167+
- **utils/**: Utility functions.
168+
- **index.ts**: Functions like filtering enabled tools.
169+
- **markdown/**: Markdown conversion functionality.
170+
- **index.ts**: Logic for converting JSON responses to Markdown format.
171+
129172
## Tools
130173

131174
All tools support the following optional parameter:
@@ -284,4 +327,4 @@ All tools support the following optional parameter:
284327

285328
## License
286329

287-
This MCP server is licensed under the MIT License. This means you are free to use, modify, and distribute the software, subject to the terms and conditions of the MIT License. For more details, please see the LICENSE file in the project repository.
330+
This MCP server is licensed under the MIT License. This means you are free to use, modify, and distribute the software, subject to the terms and conditions of the MIT License. For more details, please see the LICENSE file in the project repository.

notion/src/client.test.ts

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
import { expect, test, describe, vi, beforeEach } from "vitest";
2-
import { NotionClientWrapper } from "./index.js";
2+
import { NotionClientWrapper } from "./client/index.js";
33
import { PageResponse } from "./types/index.js";
4-
import { filterTools } from "./index.js";
4+
import { filterTools } from "./utils/index.js";
55

66
vi.mock("./markdown/index.js", () => ({
77
convertToMarkdown: vi.fn().mockReturnValue("# Test"),
88
}));
99

1010
// Mock tool list
11-
const mockInputSchema = { type: "object" as const }
11+
const mockInputSchema = { type: "object" as const };
1212
const mockTools = [
13-
{
14-
name: "notion_retrieve_block",
15-
inputSchema: mockInputSchema
16-
},
17-
{
18-
name: "notion_retrieve_page",
19-
inputSchema: mockInputSchema
20-
},
21-
{
22-
name: "notion_query_database",
23-
inputSchema: mockInputSchema
24-
}
13+
{
14+
name: "notion_retrieve_block",
15+
inputSchema: mockInputSchema,
16+
},
17+
{
18+
name: "notion_retrieve_page",
19+
inputSchema: mockInputSchema,
20+
},
21+
{
22+
name: "notion_query_database",
23+
inputSchema: mockInputSchema,
24+
},
2525
];
2626
global.fetch = vi.fn();
2727

@@ -187,11 +187,14 @@ describe("NotionClientWrapper", () => {
187187
});
188188

189189
test("should filter tools based on enabledTools", () => {
190-
const enabledToolsSet = new Set(["notion_retrieve_block", "notion_query_database"]);
190+
const enabledToolsSet = new Set([
191+
"notion_retrieve_block",
192+
"notion_query_database",
193+
]);
191194
const result = filterTools(mockTools, enabledToolsSet);
192195
expect(result).toEqual([
193196
{ name: "notion_retrieve_block", inputSchema: mockInputSchema },
194-
{ name: "notion_query_database", inputSchema: mockInputSchema }
197+
{ name: "notion_query_database", inputSchema: mockInputSchema },
195198
]);
196199
});
197200

0 commit comments

Comments
 (0)