Skip to content

Add get_exports tool for symbol discovery - #50

Closed
vitalis wants to merge 2 commits into
tidewave-ai:mainfrom
vitalis:feature/list-exports
Closed

Add get_exports tool for symbol discovery#50
vitalis wants to merge 2 commits into
tidewave-ai:mainfrom
vitalis:feature/list-exports

Conversation

@vitalis

@vitalis vitalis commented Jan 10, 2026

Copy link
Copy Markdown

Summary

  • New MCP tool get_exports to list all exported symbols from a module
  • Returns export names with line numbers, sorted by line
  • Supports local files, npm dependencies, and subpath exports
  • CLI command: tidewave exports <module>

Example

$ tidewave exports ./src/core.ts
Exports from ./src/core.ts (16 symbols):

CONSTANT_STRING:2
CONSTANT_NUMBER:3
namedFunction:9
SimpleClass:19
SimpleInterface:25
...

Test plan

  • bun run type:check passes
  • bun run lint passes
  • bun test passes (includes new integration test with comprehensive fixture)

@josevalim

Copy link
Copy Markdown
Contributor

Hi @vitalis, thank you for the PR! We have discussed this in the past and we have debated if this is worth compared to reading the source, something models are well trained to deal with, which they can also grep, and may potentially even give them more context.

@josevalim

Copy link
Copy Markdown
Contributor

And if we want to go down this route, we should also answer:

  1. Should we also include the types of each entry?
  2. Do we also want to include properties/methods for classes or interfaces? Alternatively we don't do it by default, but we allow you to list_exports a given interface/class

As far as use cases go, I can see this being useful when the agent gets an import wrong and potentially for dependencies. But probably not worth it within your own code base.

@vitalis

vitalis commented Jan 11, 2026

Copy link
Copy Markdown
Author

Hey @josevalim .. long time.. :)
I'll explain why I did it and how it helps me much now.. I'm using this branch locally..

This is from official Expo docs: (https://docs.expo.dev/versions/latest/sdk/ui/swift-ui/)


Full documentation is not yet available. Use TypeScript types to explore the API.

// Import from the SwiftUI package
import { BottomSheet } from '@expo/ui/swift-ui';

There are many TypeScript types that are not documented.. and it works amazing with the get_docs tool, I don't think there is any need to add something to it..
It also helped with Typed mocks for Expo..

Unfortunately the js/ts ecosystem is far far away from Elixir's ..
And huge thank you for Tidewave.. it's Amazing!! Please continue creating great things :)

@josevalim

Copy link
Copy Markdown
Contributor

@vitalis can you please do the following changes?

  • Rename it to get_exports
  • Add an integration test at test/integration.test. You can look at the existing tests but what you want is a fixture file that has every symbol that could be exported: classes, namespaces, functions, constants, etc (a coding agent can help write this fixture). Create a single integration test + fixture, which we assert all at once (no need for several tests)
  • Let's also include the line of each export if possible

@vitalis

vitalis commented Jan 11, 2026

Copy link
Copy Markdown
Author

@josevalim, yes, not a problem.. I'll push the changes in a day or two

@vitalis
vitalis force-pushed the feature/list-exports branch from fe1bd27 to 3ba3572 Compare January 11, 2026 10:54
@vitalis vitalis changed the title Add list_exports tool for symbol discovery Add get_exports tool for symbol discovery Jan 11, 2026
@vitalis
vitalis force-pushed the feature/list-exports branch from 3ba3572 to 88d636e Compare January 11, 2026 10:57
@vitalis

vitalis commented Jan 11, 2026

Copy link
Copy Markdown
Author

@josevalim updated, tnx

Comment thread test/integration.test.ts Outdated
Comment thread test/integration.test.ts Outdated
Comment thread test/integration.test.ts
Comment thread src/core.ts Outdated
- New MCP tool `get_exports` to list all exported symbols from a module
- Returns export names with line numbers, sorted by line
- Supports local files, npm dependencies, and subpath exports
- CLI command: `tidewave exports <module>`
- Includes integration test with comprehensive fixture covering all export types
  (constants, variables, functions, classes, interfaces, types, enums, namespaces)
@vitalis
vitalis force-pushed the feature/list-exports branch from 88d636e to 479b265 Compare January 11, 2026 12:12
Signed-off-by: José Valim <jose.valim@dashbit.co>
@josevalim

Copy link
Copy Markdown
Contributor

Looks excellent now! I will discuss with team and decide how to move forward!

@josevalim

Copy link
Copy Markdown
Contributor

Oh, there is another approach we can take here, which is to merge this with get_docs. If you use get_docs with a file path, it lists its docs and all entries in it. This will work pretty well with the fact that JSDoc also supports a @fileoverview:

/**
 * @fileoverview Utility functions for user authentication and session management.
 * @module auth/utils
 * @author Jane Doe
 * @version 1.2.0
 */

Which could be retrieved as:

import ts from 'typescript';

function getFileOverview(sourceFile) {
  // Get the first statement or the source file itself
  const firstStatement = sourceFile.statements[0];
  
  // Check for JSDoc on the source file node
  const jsDocComments = ts.getJSDocCommentsAndTags(sourceFile);
  
  if (jsDocComments.length > 0) {
    for (const jsDoc of jsDocComments) {
      if (ts.isJSDoc(jsDoc)) {
        // Get the comment text
        const comment = jsDoc.comment;
        
        // Get specific tags like @fileoverview
        const tags = jsDoc.tags || [];
        for (const tag of tags) {
          if (tag.tagName.text === 'fileoverview' || tag.tagName.text === 'file') {
            console.log('File overview:', tag.comment);
          }
        }
      }
    }
  }
  
  return null;
}

// Usage
const program = ts.createProgram(['your-file.ts'], {});
const sourceFile = program.getSourceFile('your-file.ts');
getFileOverview(sourceFile);

@josevalim

Copy link
Copy Markdown
Contributor

Then we have a separate question in which if we should support similar for the other languages. Python could have a similar API to the JS one. For Elixir and Ruby it is a slightly separate discussion, as they don't really have file based APIs.

@josevalim

Copy link
Copy Markdown
Contributor

Hi @vitalis, this has been made part of get_docs here: #52

Thank you for the initial implementation and the suggestion!

@josevalim josevalim closed this Jan 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants