gwanli 0.1.0 → 0.2.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.
Files changed (3) hide show
  1. package/dist/cli.js +50 -8
  2. package/dist/mcp.js +45 -19
  3. package/package.json +3 -3
package/dist/cli.js CHANGED
@@ -1,15 +1,57 @@
1
1
  #!/usr/bin/env node
2
- import { Command } from 'commander';
3
- import { helloGwanli } from 'gwanli-core';
4
- const program = new Command('gwanli');
2
+ import { Command } from "commander";
3
+ import { helloGwanli, indexNotionPages } from "gwanli-core";
4
+ import { exec } from "child_process";
5
+ const program = new Command("gwanli");
5
6
  program
6
- .name('gwanli')
7
- .description('Gwanli - Notion management CLI')
8
- .version('0.1.0');
7
+ .name("gwanli")
8
+ .description("Gwanli - Notion management CLI")
9
+ .version("0.1.0");
9
10
  program
10
- .command('hello')
11
- .description('Say hello from Gwanli')
11
+ .command("hello")
12
+ .description("Say hello from Gwanli")
12
13
  .action(() => {
13
14
  console.log(helloGwanli());
14
15
  });
16
+ program
17
+ .command("index")
18
+ .description("Index pages from your Notion workspace")
19
+ .option("-t, --token <token>", "Notion integration token")
20
+ .option("-d, --db <dbPath>", "Path to the SQLite database file")
21
+ .action(async (options) => {
22
+ const token = options.token || process.env.NOTION_API_KEY;
23
+ const dbPath = options.db || "./notion.db";
24
+ if (!token) {
25
+ console.error("Error: Notion token is required. Provide it via --token option or NOTION_API_KEY environment variable.");
26
+ process.exit(1);
27
+ }
28
+ await indexNotionPages(token, dbPath);
29
+ });
30
+ program
31
+ .command("auth")
32
+ .description("Interactively generate a Notion API token")
33
+ .action(async () => {
34
+ console.log("\nšŸ” Notion API Token Generator");
35
+ console.log("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
36
+ console.log("\nšŸš€ Opening authentication page in your browser...");
37
+ const workerUrl = "https://worker.ivanleomk9297.workers.dev";
38
+ // Open URL in default browser
39
+ const openCommand = process.platform === 'darwin' ? 'open' :
40
+ process.platform === 'win32' ? 'start' : 'xdg-open';
41
+ exec(`${openCommand} ${workerUrl}`, (error) => {
42
+ if (error) {
43
+ console.log(`\nāŒ Could not open browser automatically. Please visit: ${workerUrl}`);
44
+ }
45
+ else {
46
+ console.log(`\nāœ… Browser opened to: ${workerUrl}`);
47
+ }
48
+ });
49
+ console.log("\nAfter completing authentication:");
50
+ console.log("1. Copy the generated token");
51
+ console.log("2. Set it as an environment variable:");
52
+ console.log(" export NOTION_API_KEY=your_token_here");
53
+ console.log("\nAlternatively, you can use the --token option with any gwanli command.");
54
+ console.log("\nšŸ’” For more details about the worker, check: ./worker/index.ts");
55
+ console.log("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
56
+ });
15
57
  program.parse();
package/dist/mcp.js CHANGED
@@ -1,28 +1,54 @@
1
1
  #!/usr/bin/env node
2
- import { McpServer, ResourceTemplate } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ import { McpServer, } from "@modelcontextprotocol/sdk/server/mcp.js";
3
3
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
4
- import { z } from "zod";
4
+ import { exec } from "child_process";
5
+ import { promisify } from "util";
6
+ const execAsync = promisify(exec);
5
7
  // Create an MCP server
6
8
  const server = new McpServer({
7
9
  name: "demo-server",
8
- version: "1.0.0"
10
+ version: "1.0.0",
11
+ });
12
+ // Add auth tool
13
+ server.registerTool("auth", {
14
+ description: "Authenticate user by opening browser for API key setup or showing current status",
15
+ inputSchema: {},
16
+ }, async () => {
17
+ const notionApiKey = process.env.NOTION_API_KEY;
18
+ if (notionApiKey) {
19
+ return {
20
+ content: [
21
+ {
22
+ type: "text",
23
+ text: "User already authenticated, NOTION_API_KEY has been set",
24
+ },
25
+ ],
26
+ };
27
+ }
28
+ try {
29
+ // Open browser to authentication URL
30
+ const url = "https://worker.ivanleomk9297.workers.dev";
31
+ await execAsync(`open "${url}"`);
32
+ return {
33
+ content: [
34
+ {
35
+ type: "text",
36
+ text: `Opening browser to ${url} for authentication`,
37
+ },
38
+ ],
39
+ };
40
+ }
41
+ catch (error) {
42
+ return {
43
+ content: [
44
+ {
45
+ type: "text",
46
+ text: `Please visit https://worker.ivanleomk9297.workers.dev to authenticate`,
47
+ },
48
+ ],
49
+ };
50
+ }
9
51
  });
10
- // Add an addition tool
11
- server.registerTool("add", {
12
- description: "Add two numbers",
13
- inputSchema: { a: z.number(), b: z.number() }
14
- }, async ({ a, b }) => ({
15
- content: [{ type: "text", text: String(a + b) }]
16
- }));
17
- // Add a dynamic greeting resource
18
- server.resource("greeting", new ResourceTemplate("greeting://{name}", { list: undefined }), {
19
- description: "Dynamic greeting generator"
20
- }, async (uri, variables) => ({
21
- contents: [{
22
- uri: uri.href,
23
- text: `Hello, ${variables.name}!`
24
- }]
25
- }));
26
52
  // Start receiving messages on stdin and sending messages on stdout
27
53
  const transport = new StdioServerTransport();
28
54
  await server.connect(transport);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gwanli",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Notion management with AI capabilities - CLI and MCP server",
5
5
  "type": "module",
6
6
  "main": "dist/cli.js",
@@ -19,8 +19,8 @@
19
19
  "license": "MIT",
20
20
  "dependencies": {
21
21
  "commander": "^11.0.0",
22
- "gwanli-core": "{\n gwanli-core: 0.1.0\n}",
23
- "gwanli-mcp": "{\n gwanli-mcp: 0.1.0\n}"
22
+ "gwanli-core": "{\n gwanli-core: 0.2.0\n}",
23
+ "gwanli-mcp": "{\n gwanli-mcp: 0.2.0\n}"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@types/node": "^20.0.0",