|
1 | | -# Typescript Template (Typescript Starter Project) for Node Modules and CLIs |
2 | | - |
3 | | -- 🚀 Start coding immediately, without worrying about configuration |
4 | | -- 📰 Publish your package to NPM with only a few tweaks |
5 | | -- 🧹 Use a tidy file structure that is already set up for dev |
6 | | -- 🧪 Test suite ready to fill out |
7 | | -- 💻 Deliver a Command Line Interface version of your project |
8 | | -- ✨ Auto-format your code with Prettier |
9 | | -- 🔬 Find issues with ESLint |
10 | | -- ⚡ Includes Visual Studio Code extension recommendations and default settings, for maximum productivity out of the box |
11 | | - |
12 | | -Getting a Typescript project running |
13 | | -is a pain, since there is a lot of environment and configuration setup |
14 | | -before you can get started. If you want to be able to publish |
15 | | -your Typescript project to [npm](https://www.npmjs.com/) there is even more |
16 | | -configuration to ensure that you are only (and definitely) pushing the files |
17 | | -that are strictly needed. Finally, setting up testing can be confusing, |
18 | | -especially since test code also needs to be compiled but should not be |
19 | | -included with your published npm package. |
20 | | - |
21 | | -This starter kit aims to alleviate all the annoyance of setting up a modern |
22 | | -Typescript project for Node packages. |
23 | | - |
24 | | -## ⚠ Caveats ⚠ |
25 | | - |
26 | | -- This template is for Node, not Browser, projects. |
27 | | -- To support Node versions <14 you may need to change the `tsconfig.json` target settings. |
28 | | - |
29 | | -## Setup Guide |
30 | | - |
31 | | -### Dependencies |
32 | | - |
33 | | -- [**Node.js v13.2+**](https://nodejs.org/) (v14+ highly recommended) |
34 | | - |
35 | | -### Preparing a new project |
36 | | - |
37 | | -#### The easy way: GitHub Templates |
38 | | - |
39 | | -[This project](https://github.com/bscotch/typescript-template) is set up as a GitHub template. |
40 | | - |
41 | | -1. Click the "Use this Template" button on the project homepage to create your own |
42 | | - remote repo with everything here. Follow the prompts. |
43 | | -2. On your local machine, use GitHub Desktop to clone the repo, or |
44 | | - navigate to the parent folder where you want to keep your |
45 | | - local repo copy and run `git clone your-remote-url`. |
46 | | - |
47 | | -#### The hard way: All CLI, all the time |
48 | | - |
49 | | -1. Create a new remote repo on your host (e.g. GitHub, BitBucket, GitLab, etc.) |
50 | | -1. Go to the local parent folder into which you want to put your new Typescript project |
51 | | - (via your file explorer or a terminal) |
52 | | -1. Clone this repo locally: `git clone --branch develop git@github.com:bscotch/typescript-template.git` |
53 | | -1. Rename the folder containing this repo (`typescript-template`) to your project's name |
54 | | -1. Go to your new local repo (via a Git GUI or a terminal (with `cd your-new-name`)) |
55 | | -1. (Optional) If you don't want the git history from this template to be included in your project's history: |
56 | | -1. Delete the `.git` folder |
57 | | -1. Run `git init` (or use a Git GUI to initialize the repo) |
58 | | -1. Change the remote to your own remote repository: `git remote set-url origin your-remote-url` (or, if you initialized a new repo, add your remote with `git remote add origin your-remote-url`) |
59 | | - |
60 | | -#### Customize the template |
61 | | - |
62 | | -1. Run `npm install` to install all dependencies |
63 | | -2. (Optional) Run `npm outdated` to see if any dependencies have major updates. |
64 | | -3. (Optional) Run `npm update` to get those dependencies up to date with minor updates. |
65 | | -4. Update the `package.json` with your project's details |
66 | | - - Set the `name` field. If you are going to publish to npm, this will be the name of your package. Must be a URL-friendly name. Best practice is to use kebab-case (all lower-case, alphanumeric and dashes). |
67 | | - - Set the `description` field. |
68 | | - - Set the `repository` field to your remote git repo's URL. |
69 | | - - Set the `homepage` field (your remote git repo's URL works fine for this). |
70 | | - - Add any `keywords` strings. If you publish to npm, these will be used by searches. |
71 | | - - Remove the `private` field **if you want to publish to npm**. |
72 | | - - If you do not want to publish to npm, remove `&& npm publish` from the `scripts.postversion` script. |
73 | | -5. Check the `.gitignore` and add any filetypes or folders you want to keep out of your repo. |
74 | | -6. Remove any stuff from the template that you don't care about. (You can do this at any time.) |
75 | | -7. Open up the `./tsconfig.json` file to see if you want to change anything. Pay particular attention to the `paths` section! |
76 | | -8. Commit all your changes: `git add -A; git commit` |
77 | | -9. Push your commit: `git push` |
78 | | - |
79 | | -### Begin coding! |
80 | | - |
81 | | -- Your entrypoint is `./src/index.ts`, so start there! |
82 | | -- Your compiled code will appear in a git-ignored `build` folder, with entrypoint `build/index.js`. |
83 | | -- To compile, run `npm run build` |
84 | | -- To auto-recompile while you code, run `npm run build-live` |
85 | | -- Sample folders and files for types and your code library are placed in `src/lib` and `src/types`. |
86 | | -- If you intend to use the `fs-extra` module for anything in your non-test code, |
87 | | - move it from the `devDependencies` to the `dependencies` section of your `package.json`. |
88 | | - |
89 | | -### Creating a CLI (Command Line Interface) |
90 | | - |
91 | | -This template project comes with the [commander module](https://www.npmjs.com/package/commander), |
92 | | -which is great for rapidly building command line interfaces |
93 | | -(uninstall it with `npm uninstall commander` if you don't need to make a CLI). |
94 | | - |
95 | | -To create a CLI that will become available when someone installs your npm package: |
96 | | - |
97 | | -- Rename `src/cli/cli.ts` to `src/cli/your-main-cli-name.ts`. This is the entrypoint |
98 | | - for your CLI. |
99 | | -- Name any subcommand files to `src/cli/your-main-cli-name-subcommand.ts`. |
100 | | - Update the CLI entrypoint to use the same subcommand names. |
101 | | - Subcommand scripts _must_ start with the same name as your main CLI script, |
102 | | - and _must_ end with an exact command name listed by its parent script |
103 | | - (one of the `cli.command()` values). |
104 | | -- Modify the CLI templates to do whatever it's all supposed to do. |
105 | | -- To make `your-cli-command` available to users who install your |
106 | | - npm package, add the `bin` field to your `package.json`, like so: |
107 | | - ```jsonc |
108 | | - { |
109 | | - //... other root package.json options |
110 | | - "bin": { |
111 | | - "your-cli-command": "build/cli/your-main-cli-name.js" |
112 | | - } |
| 1 | +# @gleanwork/server-glean |
| 2 | + |
| 3 | +A Model Context Protocol (MCP) server implementation for Glean's search and chat capabilities. This server provides a standardized interface for AI models to interact with Glean's content search and conversational AI features through stdio communication. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- 🔍 **Search Integration**: Access Glean's powerful content search capabilities |
| 8 | +- 💬 **Chat Interface**: Interact with Glean's AI assistant |
| 9 | +- 🔄 **MCP Compliant**: Implements the Model Context Protocol specification |
| 10 | + |
| 11 | +## Prerequisites |
| 12 | + |
| 13 | +- Node.js v18 or higher |
| 14 | +- Glean API credentials |
| 15 | + |
| 16 | +## Installation |
| 17 | + |
| 18 | +```bash |
| 19 | +npm install @gleanwork/server-glean |
| 20 | +``` |
| 21 | + |
| 22 | +## Configuration |
| 23 | + |
| 24 | +1. Set up your Glean API credentials: |
| 25 | + |
| 26 | +```bash |
| 27 | +export GLEAN_SUBDOMAIN=your_subdomain |
| 28 | +export GLEAN_API_TOKEN=your_api_token |
| 29 | +``` |
| 30 | + |
| 31 | +1. (Optional) For global tokens that support impersonation: |
| 32 | + |
| 33 | +```bash |
| 34 | +export GLEAN_ACT_AS=user@example.com |
| 35 | +``` |
| 36 | + |
| 37 | +## Tools |
| 38 | + |
| 39 | +### search |
| 40 | + |
| 41 | +Search Glean's content index |
| 42 | + |
| 43 | +- **query** (string): Search query terms |
| 44 | +- **cursor** (string, optional): Pagination cursor for fetching next page |
| 45 | +- **disableSpellcheck** (boolean, optional): Disable spellcheck suggestions |
| 46 | +- **maxSnippetSize** (number, optional): Maximum size of content snippets |
| 47 | +- **pageSize** (number, optional): Number of results to return |
| 48 | +- **people** (array, optional): People to filter results by |
| 49 | + - **name** (string): Person's name |
| 50 | + - **obfuscatedId** (string): Person's unique identifier |
| 51 | + - **email** (string, optional): Person's email |
| 52 | + - **metadata** (any, optional): Additional person metadata |
| 53 | +- **resultTabIds** (array of string, optional): IDs of result tabs to include |
| 54 | +- **timeoutMillis** (number, optional): Search timeout in milliseconds |
| 55 | +- **timestamp** (string, optional): ISO 8601 timestamp of client request |
| 56 | +- **trackingToken** (string, optional): Previous tracking token for same query |
| 57 | + |
| 58 | +For complete parameter details, see [Search API Documentation](https://developers.glean.com/client/operation/search/) |
| 59 | + |
| 60 | +### chat |
| 61 | + |
| 62 | +Interact with Glean's AI assistant |
| 63 | + |
| 64 | +- **messages** (array): Array of chat messages |
| 65 | + - **agentConfig** (object, optional) |
| 66 | + - **agent** (string, optional): Name of the agent ('DEFAULT' or 'GPT') |
| 67 | + - **mode** (string, optional): Chat mode ('DEFAULT' or 'QUICK') |
| 68 | + - **author** (string): Message author ('USER' or 'GLEAN_AI') |
| 69 | + - **fragments** (array): Message content fragments |
| 70 | + - **text** (string, optional): Fragment text content |
| 71 | + - **action** (object, optional): Action parameters |
| 72 | + - **file** (object, optional): File reference |
| 73 | + - **id** (string): File ID |
| 74 | + - **name** (string): File name |
| 75 | + - **messageId** (string, optional): Unique message identifier |
| 76 | + - **messageType** (string, optional): Type of message ('UPDATE', 'CONTENT', 'CONTEXT', etc.) |
| 77 | + - **ts** (string, optional): Timestamp |
| 78 | + - **uploadedFileIds** (array of string, optional): IDs of uploaded files |
| 79 | +- **timezoneOffset** (number, optional): Client timezone offset |
| 80 | +- **agentConfig** (object, optional): Same structure as message agentConfig |
| 81 | +- **applicationId** (string, optional): Client application identifier |
| 82 | +- **chatId** (string, optional): Existing conversation ID |
| 83 | +- **saveChat** (boolean, optional): Save conversation history |
| 84 | +- **stream** (boolean, optional): Enable streaming response |
| 85 | +- **timeoutMillis** (number, optional): Chat timeout in milliseconds |
| 86 | + |
| 87 | +For complete parameter details, see [Chat API Documentation](https://developers.glean.com/client/operation/chat/) |
| 88 | + |
| 89 | +## Usage |
| 90 | + |
| 91 | +The server implements the Model Context Protocol (MCP) and communicates through stdio. All requests use the JSON-RPC 2.0 format with the `mcp.call_tool` method: |
| 92 | + |
| 93 | +```json |
| 94 | +{ |
| 95 | + "jsonrpc": "2.0", |
| 96 | + "method": "mcp.call_tool", |
| 97 | + "params": { |
| 98 | + "name": "<tool_name>", |
| 99 | + "arguments": { ... } |
113 | 100 | } |
114 | | - ``` |
115 | | - |
116 | | -Test your CLI locally by running `node build/cli/your-main-cli-name.js -h`. |
117 | | - |
118 | | -If you publish your project as an npm module, users who install it will be able |
119 | | -to run `npx your-cli-command` in their terminals, or simply `your-cli-command` |
120 | | -if they've done a global install of your module (with `npm install --global your-module-name`). |
121 | | - |
122 | | -### Testing |
123 | | - |
124 | | -- Add tests to `./src/test` as you go. |
125 | | -- Place any reference data for tests into `./samples` |
126 | | -- Run tests from the terminal with `npm test` (make sure your code is compiled first). |
127 | | -- Run tests from VSCode (click the debugger on the sidebar) to use breakpoints and allow inspection: |
128 | | - - Use the "Tests" option to run against your compiled code. |
129 | | - - Console logs will appear in the Debug Console, where you can also step through your code if you set breakpoints. |
130 | | - - Edit `./.vscode/launch.json` to add or change the tests. |
131 | | - |
132 | | -### Versioning and publishing to npm |
133 | | - |
134 | | -When you are ready to increment the version of your project, which by default |
135 | | -is coupled to publishing to `npm` and merging into your `main` branch |
136 | | -(edit this behavior in the `scripts` section of the `package.json`), |
137 | | -use the `npm version` commands. For example: |
138 | | - |
139 | | -- `npm version patch` to bump the patch version, indicated a bugfix |
140 | | -- `npm version minor` to bump the minor version, indicating a new feature (backwards-compatible) |
141 | | -- `npm version major` to bump the major version, indicating substantial and/or breaking changes |
142 | | - |
143 | | -The `preversion`, `version`, and `postversion` scripts in the `package.json` file dictate what happens |
144 | | -when you use an `npm version` command. By default, the sequence of things that happen are: |
145 | | - |
146 | | -1. Source is compiled into plain JavaScript. |
147 | | -2. Tests are run against the compiled JavaScript. If any fail, the process aborts. |
148 | | -3. Increment the version number in the `package.json` file. |
149 | | -4. Update `CHANGELOG.md` to reflect the new version. |
150 | | -5. `git add` all file changes. |
151 | | -6. Commit changes and create a version tag. |
152 | | -7. Push changes to remote |
153 | | -8. Publish package to `npm`. |
| 101 | +} |
| 102 | +``` |
| 103 | + |
| 104 | +## API Reference |
| 105 | + |
| 106 | +For detailed information about the available parameters and their usage: |
| 107 | + |
| 108 | +- Search API: [Glean Search Documentation](https://developers.glean.com/client/operation/search/) |
| 109 | +- Chat API: [Glean Chat Documentation](https://developers.glean.com/client/operation/chat/) |
| 110 | + |
| 111 | +The MCP server implements these APIs following the JSON-RPC 2.0 protocol for communication. |
| 112 | + |
| 113 | +## Error Handling |
| 114 | + |
| 115 | +The server returns standardized error responses following the JSON-RPC 2.0 specification: |
| 116 | + |
| 117 | +```json |
| 118 | +{ |
| 119 | + "jsonrpc": "2.0", |
| 120 | + "id": 2, |
| 121 | + "error": { |
| 122 | + "code": -32603, |
| 123 | + "message": "Error: Invalid authentication token" |
| 124 | + } |
| 125 | +} |
| 126 | +``` |
| 127 | + |
| 128 | +Common error scenarios: |
| 129 | + |
| 130 | +- Missing or invalid environment variables |
| 131 | +- Invalid tool parameters |
| 132 | +- Authentication failures |
| 133 | +- API timeout or connection issues |
| 134 | + |
| 135 | +## Running the Server |
| 136 | + |
| 137 | +The server communicates via stdio, making it ideal for integration with AI models and other tools: |
| 138 | + |
| 139 | +```bash |
| 140 | +node build/index.js |
| 141 | +``` |
| 142 | + |
| 143 | +Input and output follow the JSON-RPC 2.0 protocol, with each message on a new line. |
| 144 | + |
| 145 | +## Contributing |
| 146 | + |
| 147 | +Please see [CONTRIBUTING.md](CONTRIBUTING.md) for development setup and guidelines. |
| 148 | + |
| 149 | +## License |
| 150 | + |
| 151 | +MIT License - see the [LICENSE](LICENSE) file for details |
| 152 | + |
| 153 | +## Support |
| 154 | + |
| 155 | +- Documentation: [docs.glean.com](https://docs.glean.com) |
| 156 | +- Issues: [GitHub Issues](https://github.com/gleanwork/server-glean/issues) |
| 157 | +- Email: [support@glean.com](mailto:support@glean.com) |
0 commit comments